Moved attachAbstract() to class_builder
parent
35157b0e81
commit
55288f1e07
32
lib/class.js
32
lib/class.js
|
@ -356,12 +356,11 @@ function extend()
|
|||
var data = class_builder.build.apply( null, arguments ),
|
||||
|
||||
new_class = data[ 'class' ],
|
||||
abstract_methods = data.abstractMethods,
|
||||
class_id = data.classId
|
||||
;
|
||||
|
||||
// important: call after setting prototype
|
||||
setupProps( new_class, abstract_methods, class_id );
|
||||
setupProps( new_class, class_id );
|
||||
|
||||
// lock down the new class (if supported) to ensure that we can't add
|
||||
// members at runtime
|
||||
|
@ -420,45 +419,18 @@ var implement = function()
|
|||
* Sets up common properties for the provided function (class)
|
||||
*
|
||||
* @param {function()} func function (class) to set up
|
||||
* @param {Array.<string>} abstract_methods list of abstract method names
|
||||
* @param {number} class_id unique id to assign to class
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function setupProps( func, abstract_methods, class_id )
|
||||
function setupProps( func, class_id )
|
||||
{
|
||||
attachAbstract( func, abstract_methods );
|
||||
attachExtend( func );
|
||||
attachImplement( func );
|
||||
attachId( func, class_id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attaches isAbstract() method to the class
|
||||
*
|
||||
* @param {Function} func function (class) to attach method to
|
||||
* @param {Array} methods abstract method names
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function attachAbstract( 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
|
||||
*/
|
||||
util.defineSecureProp( func, 'isAbstract', function()
|
||||
{
|
||||
return is_abstract;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attaches extend method to the given function (class)
|
||||
*
|
||||
|
|
|
@ -216,12 +216,13 @@ exports.build = function extend()
|
|||
meta.abstractMethods = abstract_methods;
|
||||
meta.name = cname;
|
||||
|
||||
attachAbstract( new_class, abstract_methods );
|
||||
|
||||
// we're done with the extension process
|
||||
extending = false;
|
||||
|
||||
return {
|
||||
'class': new_class,
|
||||
abstractMethods: abstract_methods,
|
||||
classId: class_id,
|
||||
};
|
||||
};
|
||||
|
@ -726,3 +727,28 @@ exports.isInstanceOf = function( type, instance )
|
|||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Attaches isAbstract() method to the class
|
||||
*
|
||||
* @param {Function} func function (class) to attach method to
|
||||
* @param {Array} methods abstract method names
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function attachAbstract( 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
|
||||
*/
|
||||
util.defineSecureProp( func, 'isAbstract', function()
|
||||
{
|
||||
return is_abstract;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue