Added isClass() and isClassInstance() methods
parent
928a0ea297
commit
c9d0e027fa
37
lib/class.js
37
lib/class.js
|
@ -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
|
||||
*
|
||||
|
|
|
@ -44,6 +44,43 @@ assert.ok(
|
|||
"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
|
||||
if ( Object.isFrozen )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue