1
0
Fork 0

Finished refactoring to remove result_data object in class extend() function

closure/master
Mike Gerwitz 2010-12-19 13:54:31 -05:00
parent 1ff9408885
commit cd9ef1ea71
1 changed files with 14 additions and 17 deletions

View File

@ -87,12 +87,9 @@ var extend = ( function( extending )
base = args.pop() || Class,
prototype = new base();
// copy the given properties into the new prototype
var result_data = {
abstractMethods: ( base.abstractMethods || [] ).slice()
};
var properties = {},
abstract_methods = ( base.abstractMethods || [] ).slice();
var properties = {};
util.propCopy( props, prototype, {
each: function( name, value )
{
@ -117,7 +114,7 @@ var extend = ( function( extending )
if ( ( pre === undefined ) && is_abstract )
{
result_data.abstractMethods.push( name );
abstract_methods.push( name );
}
this.performDefault( name, func, is_abstract );
@ -126,20 +123,20 @@ var extend = ( function( extending )
methodOverride: function( name, pre, func )
{
return util.overrideMethod(
name, pre, func, result_data.abstractMethods
name, pre, func, abstract_methods
);
},
} );
result_data.abstractMethods = util.arrayShrink( result_data.abstractMethods );
abstract_methods = util.arrayShrink( abstract_methods );
// reference to the parent prototype (for more experienced users)
prototype.parent = base.prototype;
// set up the new class
var new_class = create_ctor( result_data );
var new_class = create_ctor( abstract_methods );
setup_props( new_class, result_data );
setup_props( new_class, abstract_methods );
attach_prop_init( prototype, properties );
new_class.prototype = prototype;
@ -162,14 +159,14 @@ var extend = ( function( extending )
* This constructor will call the __constructor method for concrete classes
* and throw an exception for abstract classes (to prevent instantiation).
*
* @param {Object} result_data data from property copy operation
* @param {Array.<string>} abstract_methods list of abstract methods
*
* @return {Function} constructor
*/
function create_ctor( result_data, properties )
function create_ctor( abstract_methods )
{
// concrete class
if ( result_data.abstractMethods.length === 0 )
if ( abstract_methods.length === 0 )
{
return function()
{
@ -200,14 +197,14 @@ var extend = ( function( extending )
/**
* Sets up common properties for the provided function (class)
*
* @param {Function} func function (class) to attach properties to
* @param {Object} class_data information about the class
* @param {Function} func function (class) to set up
* @param {Array.<string>} abstract_methods list of abstract method names
*
* @return {undefined}
*/
function setup_props( func, class_data )
function setup_props( func, abstract_methods )
{
attach_abstract( func, class_data.abstractMethods );
attach_abstract( func, abstract_methods );
attach_extend( func );
}