【发布时间】:2011-09-17 23:56:42
【问题描述】:
我正在尝试在我的代码中检查特定类型的对象。即使对象的原型中有构造函数,它仍然无法返回正确的对象类型,并且在使用 instanceof 运算符时总是返回“object”。
这是一个对象的例子:
Simple = (function(x, y, z) {
var _w = 0.0;
return {
constructor: Simple,
x: x || 0.0,
y: y || 0.0,
z: z || 0.0,
Test: function () {
this.x += 1.0;
this.y += 1.0;
this.z += 1.0;
console.log("Private: " + _w);
console.log("xyz: [" + this.x + ", " + this.y + ", " + this.z + "]");
}
}
});
【问题讨论】:
标签: javascript constructor singleton instanceof