1
0
Fork 0

Added isAbstract() method to class

closure/master
Mike Gerwitz 2010-11-14 01:10:55 -05:00
parent 716db6d086
commit de979d07f0
1 changed files with 33 additions and 7 deletions

View File

@ -98,9 +98,7 @@ function prop_copy( props, dest, result_data )
result_data = result_data || {}; result_data = result_data || {};
// initialize result_data // initialize result_data
result_data = { result_data.abstractMethods = [];
abstractMethods: [],
};
// copy each of the properties to the destination object // copy each of the properties to the destination object
for ( property in props ) for ( property in props )
@ -196,13 +194,14 @@ function extend()
}; };
// copy the given properties into the new prototype // copy the given properties into the new prototype
prop_copy( props, prototype ); var result_data = {};
prop_copy( props, prototype, result_data );
// 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
setup_props( new_class ); setup_props( new_class, result_data );
new_class.prototype = prototype; new_class.prototype = prototype;
new_class.constructor = new_class; new_class.constructor = new_class;
@ -214,15 +213,42 @@ function extend()
* 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 attach properties to
* @param {Object} class_data information about the class
* *
* @return {undefined} * @return {undefined}
*/ */
function setup_props( func ) function setup_props( func, class_data )
{ {
attach_abstract( func, class_data.abstractMethods );
attach_extend( func ); attach_extend( func );
} }
/**
* Attaches isAbstract() method to the class
*
* @param {Function} func function (class) to attach method to
* @param {Array} methods abstract method names
*
* @return {undefined}
*/
function attach_abstract( func, methods )
{
var is_abstract = ( methods.length > 0 ) ? true: false;
/**
* Returns whether the class contains abstract methods (and is therefore
* abstract)
*
* @return {Boolean} true if class is abstract, otherwise false
*/
func.isAbstract = function()
{
return is_abstract;
};
}
/** /**
* Attaches extend method to the given function (class) * Attaches extend method to the given function (class)
* *