Moved implement() into its own method, accepting destination object as the first parameter
parent
fba94f2e0b
commit
ec9f24a926
61
lib/class.js
61
lib/class.js
|
@ -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)
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue