首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript 利用call步骤实现多层次继承

2012-11-25 
javascript 利用call方法实现多层次继承利用call方法模拟面向对象程序设计中的多层次继承其实如果熟悉java

javascript 利用call方法实现多层次继承
利用call方法模拟面向对象程序设计中的多层次继承

其实如果熟悉java或其他面向对象程序设计思想,理解javascript的call方法的使用,就能很好理解了。

直接给出代码:

function GrandFather(){this.g=function(msg){alert(msg+"\n grandFather: Good Morning,grandson!");}this.g2=function(msg){alert(msg+"\n grandFather: have a good day, grandson!");}}function Father(){GrandFather.call(this);this.f=function(msg){alert(msg+"\n father:you bad boy,haha!");}}function Son(){Father.call(this);}var son = new Son();son.f("son: hi,Dad!");son.g("grandson: Morning,grandFather!");son.g2("grandson: Let me walk with you!");


热点排行