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