diff --git a/lib/class.js b/lib/class.js index 04e8048..0edaf05 100644 --- a/lib/class.js +++ b/lib/class.js @@ -98,9 +98,7 @@ function prop_copy( props, dest, result_data ) result_data = result_data || {}; // initialize result_data - result_data = { - abstractMethods: [], - }; + result_data.abstractMethods = []; // copy each of the properties to the destination object for ( property in props ) @@ -196,13 +194,14 @@ function extend() }; // 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) prototype.parent = base.prototype; // set up the new class - setup_props( new_class ); + setup_props( new_class, result_data ); new_class.prototype = prototype; new_class.constructor = new_class; @@ -213,16 +212,43 @@ function extend() /** * 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} */ -function setup_props( func ) +function setup_props( func, class_data ) { + attach_abstract( func, class_data.abstractMethods ); 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) *