1
0
Fork 0

Added isClass() and isClassInstance() methods

closure/master
Mike Gerwitz 2010-12-28 20:58:42 -05:00
parent 928a0ea297
commit c9d0e027fa
2 changed files with 74 additions and 0 deletions

View File

@ -39,6 +39,43 @@ exports.extend = function( base )
} }
/**
* Determines whether the provided object is a class created through ease.js
*
* @param {Object} obj object to test
*
* @return {boolean} true if class (created through ease.js), otherwise false
*/
exports.isClass = function( obj )
{
obj = obj || {};
return ( obj.prototype instanceof Class )
? true
: false
;
};
/**
* Determines whether the provided object is an instance of a class created
* through ease.js
*
* @param {Object} obj object to test
*
* @return {boolean} true if instance of class (created through ease.js),
* otherwise false
*/
exports.isClassInstance = function( obj )
{
obj = obj || {};
return ( obj instanceof Class )
? true
: false;
};
/** /**
* Default class implementation * Default class implementation
* *

View File

@ -44,6 +44,43 @@ assert.ok(
"Extend method creates a new object" "Extend method creates a new object"
); );
assert.ok(
( Class.isClass( Class.extend() ) ),
"Classes are considered by the system to be classes"
);
//
// isClass
assert.ok(
( !( Class.isClass( {} ) ) ),
"Only actual classes are considered to be classes"
);
assert.ok(
( !( Class.isClass( new Foo() ) ) ),
"Class instances are not considered to be classes (they are objects)"
);
//
// isClassInstance
assert.ok(
( Class.isClassInstance( new Foo() ) ),
"Class instances are considered to be classes instances"
);
assert.ok(
( !( Class.isClassInstance( Foo ) ) ),
"Classes are not considered to be class instances"
);
assert.ok(
( !( Class.isClassInstance( {} ) ) ),
"Other objects are not considered to be class instances"
);
// only perform check if supported by the engine // only perform check if supported by the engine
if ( Object.isFrozen ) if ( Object.isFrozen )
{ {