Added isA() as an alias for isInstanceOf()
parent
6a24f2ad13
commit
76969201fb
17
lib/class.js
17
lib/class.js
|
@ -106,6 +106,16 @@ exports.isInstanceOf = function( type, instance )
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for isInstanceOf()
|
||||||
|
*
|
||||||
|
* May read better in certain situations (e.g. Cat.isA( Mammal )) and more
|
||||||
|
* accurately conveys the act of inheritance, implementing interfaces and
|
||||||
|
* traits, etc.
|
||||||
|
*/
|
||||||
|
exports.isA = exports.isInstanceOf;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default class implementation
|
* Default class implementation
|
||||||
*
|
*
|
||||||
|
@ -399,9 +409,12 @@ function attachExtend( func )
|
||||||
*/
|
*/
|
||||||
function attachInstanceOf( instance )
|
function attachInstanceOf( instance )
|
||||||
{
|
{
|
||||||
util.defineSecureProp( instance, 'isInstanceOf', function( type )
|
var method = function( type )
|
||||||
{
|
{
|
||||||
return exports.isInstanceOf( type, instance );
|
return exports.isInstanceOf( type, instance );
|
||||||
});
|
};
|
||||||
|
|
||||||
|
util.defineSecureProp( instance, 'isInstanceOf', method );
|
||||||
|
util.defineSecureProp( instance, 'isA', method );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,12 @@ assert.ok(
|
||||||
"Class is not an instance of its instance"
|
"Class is not an instance of its instance"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
Class.isInstanceOf,
|
||||||
|
Class.isA,
|
||||||
|
"isA() is an alias for isInstanceOf()"
|
||||||
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( ( inst.isInstanceOf instanceof Function )
|
( ( inst.isInstanceOf instanceof Function )
|
||||||
&& ( inst.isInstanceOf( Foo ) === true )
|
&& ( inst.isInstanceOf( Foo ) === true )
|
||||||
|
@ -120,3 +126,9 @@ assert.ok(
|
||||||
"Class instance contains partially applied isInstanceOf method"
|
"Class instance contains partially applied isInstanceOf method"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
inst.isInstanceOf,
|
||||||
|
inst.isA,
|
||||||
|
"Class instance contains isA() alias for isInstanceOf() partially applied function"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue