1
0
Fork 0

Moved implement() into its own method, accepting destination object as the first parameter

closure/master
Mike Gerwitz 2011-01-10 19:00:26 -05:00
parent fba94f2e0b
commit ec9f24a926
1 changed files with 42 additions and 19 deletions

View File

@ -57,27 +57,12 @@ exports.extend = function( base )
*/ */
exports.implement = function() exports.implement = function()
{ {
var len = arguments.length, var args = Array.prototype.slice.call( arguments );
dest = {},
arg = null,
abstract_list = [], // apply to an empty (new) object
implemented = []; args.unshift( {} );
// add each of the interfaces return implement.apply( this, args );
for ( var i = 0; i < len; i++ )
{
arg = arguments[ i ];
// copy all interface methods to the class (does not yet deep copy)
util.propCopy( arg.prototype, dest );
implemented.push( arg );
}
var class_new = exports.extend( dest );
getMeta( class_new.__cid ).implemented = implemented;
return class_new;
}; };
@ -359,6 +344,44 @@ var extend = ( function( extending )
} )( false ); } )( false );
/**
* Implements interface(s) into an object
*
* This will copy all of the abstract methods from the interface into the
* destination object.
*
* @param {Object} dest destination object
* @param {...Interface} interfaces interfaces to implement into dest
*
* @return {Object} destination object with interfaces implemented
*/
var implement = function()
{
var args = Array.prototype.slice.call( arguments ),
dest = args.shift(),
len = args.length,
arg = null,
abstract_list = [],
implemented = [];
// add each of the interfaces
for ( var i = 0; i < len; i++ )
{
arg = args[ i ];
// copy all interface methods to the class (does not yet deep copy)
util.propCopy( arg.prototype, dest );
implemented.push( arg );
}
var class_new = exports.extend( dest );
getMeta( class_new.__cid ).implemented = implemented;
return class_new;
}
/** /**
* Sets up common properties for the provided function (class) * Sets up common properties for the provided function (class)
* *