Moved attachAbstract() to class_builder
parent
35157b0e81
commit
55288f1e07
40
lib/class.js
40
lib/class.js
|
@ -355,13 +355,12 @@ function extend()
|
||||||
// set up the new class
|
// set up the new class
|
||||||
var data = class_builder.build.apply( null, arguments ),
|
var data = class_builder.build.apply( null, arguments ),
|
||||||
|
|
||||||
new_class = data[ 'class' ],
|
new_class = data[ 'class' ],
|
||||||
abstract_methods = data.abstractMethods,
|
class_id = data.classId
|
||||||
class_id = data.classId
|
|
||||||
;
|
;
|
||||||
|
|
||||||
// important: call after setting prototype
|
// 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
|
// lock down the new class (if supported) to ensure that we can't add
|
||||||
// members at runtime
|
// members at runtime
|
||||||
|
@ -419,46 +418,19 @@ var implement = function()
|
||||||
/**
|
/**
|
||||||
* Sets up common properties for the provided function (class)
|
* Sets up common properties for the provided function (class)
|
||||||
*
|
*
|
||||||
* @param {function()} func function (class) to set up
|
* @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
|
||||||
* @param {number} class_id unique id to assign to class
|
|
||||||
*
|
*
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
function setupProps( func, abstract_methods, class_id )
|
function setupProps( func, class_id )
|
||||||
{
|
{
|
||||||
attachAbstract( func, abstract_methods );
|
|
||||||
attachExtend( func );
|
attachExtend( func );
|
||||||
attachImplement( func );
|
attachImplement( func );
|
||||||
attachId( func, class_id );
|
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)
|
* Attaches extend method to the given function (class)
|
||||||
*
|
*
|
||||||
|
|
|
@ -216,13 +216,14 @@ exports.build = function extend()
|
||||||
meta.abstractMethods = abstract_methods;
|
meta.abstractMethods = abstract_methods;
|
||||||
meta.name = cname;
|
meta.name = cname;
|
||||||
|
|
||||||
|
attachAbstract( new_class, abstract_methods );
|
||||||
|
|
||||||
// we're done with the extension process
|
// we're done with the extension process
|
||||||
extending = false;
|
extending = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'class': new_class,
|
'class': new_class,
|
||||||
abstractMethods: abstract_methods,
|
classId: class_id,
|
||||||
classId: class_id,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -726,3 +727,28 @@ exports.isInstanceOf = function( type, instance )
|
||||||
return false;
|
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