当前位置: 代码迷 >> JavaScript >> javascript 利用call步骤实现多层次继承
  详细解决方案

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

热度:116   发布时间:2012-11-25 11:44:31.0
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!");


  相关解决方案