1
0
Fork 0

Added isA() as an alias for isInstanceOf()

closure/master
Mike Gerwitz 2010-12-29 21:37:11 -05:00
parent 6a24f2ad13
commit 76969201fb
2 changed files with 27 additions and 2 deletions

View File

@ -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 );
} }

View File

@ -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"
);