首页 > 其他 > 详细

原型问题2—原型对象的替换

时间:2018-06-27 13:06:05      阅读:194      评论:0      收藏:0      [点我收藏+]
function Animal(){
   this.type = "Animal"; 
} 
Animal.prototype.say = function(){ 
  console.log(this.type); 
} 
function Cat(){   
this.vioce = "喵喵喵"; } Cat.prototype = new Animal(); Cat.prototype = { //这样会使上一条语句失效,从而使原型链断开。
  shout:function(){
   console.log(this.vioce); } }

Cat.prototype为什么会失效:

因为{}是一个新的对象,所以Cat.prototype的旧原型链就会断掉

原型问题2—原型对象的替换

原文:https://www.cnblogs.com/jokes/p/9233364.html

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