首页 > 其他 > 详细

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

时间:2016-05-23 00:50:07      阅读:133      评论:0      收藏:0      [点我收藏+]
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自己的方法,完全可以使用这样的方式实现继承。

 

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

原文:http://www.cnblogs.com/pick7/p/5518391.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!