【发布时间】:2016-04-05 21:10:14
【问题描述】:
我创建了一个人类。当我将它实例化为daffyDuck 实例时,它不会被识别为A_person 的实例。为什么不呢?
var A_person = function(firstAndLast) {
var splitName = firstAndLast.split(" ");
return {
getFullName: function(){
return splitName.join(" ");
}
};
};
var daffyDuck = new A_person('Daffy Duck');
daffyDuck instanceof A_person // false (I expected this to be true!)
【问题讨论】:
-
您从您的
constructor返回一个different object,这绝对不是instance ofA_person。这是我能想到的。尝试返回this并检查一下。
标签: javascript