个人思考:能否sub.prototye=sup.prototype实现继承

var Sup=function(name){
	this.name=name;
};
var Sub=function(name){
	this.name=name;
};
Sup.prototype.sayName=function(){
	alert(this.name);
}
Sub.prototype=Sup.prototype;
Sup.prototype.sayAge=function(){
	alert(21);
}
Sub.prototye.sayMe=function(){
	alert("me");
}
var instance=new Sub("gao");
instance.sayName();		//gao	
instance.sayAge();	//21
instance.sayMe();   //不能执行,sayMe函数不能被定义

  Sub.prototype=Sup.prototype是可以执行的,同时也实现了继承,在Sup.prototype中添加方法可以成功,而在Sub.prototype添加方法会失败。如果仅仅是想继承Sup.prototype的方法,而不用添加Sub.prototype自己的方法,完全可以使用这样的方式实现继承。

 

posted @ 2016-05-22 23:43  拾七  阅读(264)  评论(3编辑  收藏  举报