0

为什么下面的对象工厂模式代码返回false...

var Animal = function(name) {
var temp = new Object();
    temp.name = name;
    return temp;
}

var animal = Animal("fox");

console.log(animal instanceof Animal);

...而以下构造函数模式代码返回 true;

var Animal = function(name) {
    this.name = name;
}

var animal = new Animal("fox");

console.log(animal instanceof Animal);
4

0 回答 0