function Animal(){
this.species = "动物";
}
function Cat(name,color){
this.name = name;
this.color = color;
}
Cat.prototype = new Animal();
Cat.prototype.constructor = Cat;
//Cat的原型指向了 Animal生成的对象,此时Cat 和Animal
不是引用了同一个原型吗 ,将Cat的构造器覆盖了 不也会
同时覆盖 Animal的构造器吗? 所以下面这句为什么不是false而
是true
alert(Animal.prototype.constructor == Animal); // true
Cat.prototype = new Animal(); 这一步 将Cat.prototype修改为Animal 的实例
此时的 Cat.prototype.constructor 的确是等于 Animal
但是 Cat.prototype 里面并没有 constructor 属性,Cat.prototype.constructor === Animal()只是因为在自身找不到 constructor 属性,所以找到了 Animal.prototype ;
Cat.prototype.constructor = Cat; 这一步 为Cat.prototype 新增了 constructor 熟悉,但并不影响 Animal.prototype.constructor