我工作的一个Javascript和我被困了一些验证:如何检查的instanceof对象的实例,在Javascript
我想检查作为参数变量是一个实例一个对象的实例。为了更清楚,这里有一个例子:
var Example = function() {
console.log ('Meta constructor');
return function() {
console.log ('Instance of the instance !');
};
};
var inst = new Example();
assertTrue(inst instanceof Example.constructor); // ok
var subInst = new inst();
assertTrue(subInst instanceof Example.constructor); // FAIL
assertTrue(subinst instanceof inst.constructor); // FAIL
我如何检查subInst
是Example.{new}
一个实例?或inst.constructor
?
谢谢! :)
检查了这一点 http://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript – TheITGuy