javascript - js question, please answer
PHPz
PHPz 2017-05-19 10:34:49
0
1
672
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
PHPz
PHPz

学习是最好的投资!

reply all(1)
Peter_Zhu

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.一般构造函数不返回值的。function Dog() { return new Animal};new Dog()等同于创建了 Animal instance. I don’t know if my analysis is correct or not. Comments are welcome.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template