Object class masquerading
parent
98e76be94f
commit
69e9828beb
|
@ -242,6 +242,30 @@ exports.getMeta = function( cls )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow OBJ to assume an identity as a class
|
||||||
|
*
|
||||||
|
* This is useful to use objects in situations where classes are expected,
|
||||||
|
* as it eliminates the need for handling of special cases.
|
||||||
|
*
|
||||||
|
* This is intended for internal use---there are no guarantees as to what
|
||||||
|
* methods ease.js may expect that a class-like object incorporate. That
|
||||||
|
* guarantee may exist in the future, but until then, stay away.
|
||||||
|
*
|
||||||
|
* @param {Object} obj object to masquerade as an ease.js class
|
||||||
|
*
|
||||||
|
* @return {Object} OBJ
|
||||||
|
*/
|
||||||
|
exports.masquerade = function( obj )
|
||||||
|
{
|
||||||
|
// XXX: this is duplicated; abstract
|
||||||
|
util.defineSecureProp( obj, _priv, {} );
|
||||||
|
|
||||||
|
createMeta( obj, exports.ClassBase );
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the class is an instance of the given type
|
* Determines if the class is an instance of the given type
|
||||||
*
|
*
|
||||||
|
@ -1461,4 +1485,3 @@ function attachFlags( ctor, props )
|
||||||
// (v8 performance)
|
// (v8 performance)
|
||||||
props.___$$final$$ = props.___$$abstract$$ = undefined;
|
props.___$$final$$ = props.___$$abstract$$ = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,11 +179,6 @@ module.exports.isClass = function( obj )
|
||||||
{
|
{
|
||||||
obj = obj || _dummyclass;
|
obj = obj || _dummyclass;
|
||||||
|
|
||||||
if ( !obj.prototype )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var meta = ClassBuilder.getMeta( obj );
|
var meta = ClassBuilder.getMeta( obj );
|
||||||
|
|
||||||
// TODO: we're checking a random field on the meta object; do something
|
// TODO: we're checking a random field on the meta object; do something
|
||||||
|
|
|
@ -25,6 +25,7 @@ require( 'common' ).testCase(
|
||||||
setUp: function()
|
setUp: function()
|
||||||
{
|
{
|
||||||
this.Sut = this.require( 'class' );
|
this.Sut = this.require( 'class' );
|
||||||
|
this.ClassBuilder = this.require( 'ClassBuilder' );
|
||||||
|
|
||||||
this.Foo = this.Sut.extend(
|
this.Foo = this.Sut.extend(
|
||||||
{
|
{
|
||||||
|
@ -249,6 +250,21 @@ require( 'common' ).testCase(
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There are cases---intended for internal use---where it is beneficial
|
||||||
|
* for an object to be treated as though it were actually a class.
|
||||||
|
*/
|
||||||
|
'Any object may masquerade as a class': function()
|
||||||
|
{
|
||||||
|
var obj = {};
|
||||||
|
|
||||||
|
// XXX: tightly coupled logic here; refactor things
|
||||||
|
this.ClassBuilder.masquerade( obj );
|
||||||
|
|
||||||
|
this.assertOk( this.Sut.isClass( obj ) );
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This really should be encapsulated, probably, but it does exist for
|
* This really should be encapsulated, probably, but it does exist for
|
||||||
* reference.
|
* reference.
|
||||||
|
|
Loading…
Reference in New Issue