1
0
Fork 0

Moved attachAbstract() to class_builder

closure/master
Mike Gerwitz 2011-03-29 00:08:49 -04:00
parent 35157b0e81
commit 55288f1e07
2 changed files with 35 additions and 37 deletions

View File

@ -356,12 +356,11 @@ function extend()
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
@ -420,45 +419,18 @@ 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)
* *

View File

@ -216,12 +216,13 @@ 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;
});
}