function Animal() {};
function Cat() {};
function Dog() { return new Animal};
Cat.prototype = new Animal;
console.log(new Dog instanceof Animal);//true為什么?
console.log(new Dog instanceof Dog);//false 為什么?
console.log(new Cat instanceof Animal);//true
學(xué)習(xí)是最好的投資!
If the constructor returns an "object", then this object will replace the entire new result. If the constructor does not return an object, the constructor will return this by default, which is the Dog
.一般構(gòu)造函數(shù)不返回值的。function Dog() { return new Animal};new Dog()
等同于創(chuàng)建了 Animal
instance. I don’t know if my analysis is correct or not. Comments are welcome.