我想知道是否有办法确定变量是否包含MooTools类实例。
以下是jsFiddle中的示例:http://jsfiddle.net/kGnaa/
var a = new Class();
var aInstance = new a();
document.write('#1 instanceOf(aInstance,a) = ' + instanceOf(aInstance,a) + '<br>') // aInstance is instance of a. Returns true.
document.write('#2 instanceOf(aInstance,Class) = ' + instanceOf(aInstance,Class) + '<br>') // aInstance isn't instance of Class, so returns false.
有没有办法让#2发生?
答案 0 :(得分:1)
我想我明白了。
var Foo = new Class({});
var FooInstance = new Foo();
alert(typeOf(FooInstance.$constructor)); // alerts 'class'