`
dyh200896
  • 浏览: 3777 次
  • 性别: Icon_minigender_1
  • 来自: 广东
社区版块
存档分类
最新评论

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!");


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics