2

我想知道是否有办法确定变量是否包含 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发生?

4

1 回答 1

1

我想我明白了。

var Foo = new Class({});
var FooInstance = new Foo();
alert(typeOf(FooInstance.$constructor)); // alerts 'class'
于 2013-01-04T07:26:00.410 回答