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的旧原型链就会断掉