Split concrete and abstract ctor generation into two separate functions
parent
5bb0269280
commit
8ba68b31dc
|
@ -41,7 +41,16 @@ var util = require( __dirname + '/util' ),
|
|||
* Instance id counter, to be incremented on each new instance
|
||||
* @type {number}
|
||||
*/
|
||||
instance_id = 0
|
||||
instance_id = 0,
|
||||
|
||||
/**
|
||||
* Set to TRUE when class is in the process of being extended to ensure that
|
||||
* a constructor can be instantiated (to use as the prototype) without
|
||||
* invoking the class construction logic
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
extending = false
|
||||
;
|
||||
|
||||
|
||||
|
@ -71,9 +80,7 @@ var enum_bug = (
|
|||
exports.ClassBase = function Class() {};
|
||||
|
||||
|
||||
exports.build = ( function( extending )
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Mimics class inheritance
|
||||
*
|
||||
* This method will mimic inheritance by setting up the prototype with the
|
||||
|
@ -85,8 +92,8 @@ exports.build = ( function( extending )
|
|||
*
|
||||
* @return {Object} extended class
|
||||
*/
|
||||
return function extend()
|
||||
{
|
||||
exports.build = function extend()
|
||||
{
|
||||
// ensure we'll be permitted to instantiate abstract classes for the base
|
||||
extending = true;
|
||||
|
||||
|
@ -162,10 +169,10 @@ exports.build = ( function( extending )
|
|||
abstractMethods: abstract_methods,
|
||||
classId: class_id,
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Creates the constructor for a new class
|
||||
*
|
||||
* This constructor will call the __constructor method for concrete classes
|
||||
|
@ -177,11 +184,34 @@ exports.build = ( function( extending )
|
|||
*
|
||||
* @return {Function} constructor
|
||||
*/
|
||||
function createCtor( cname, abstract_methods, members )
|
||||
{
|
||||
function createCtor( cname, abstract_methods, members )
|
||||
{
|
||||
// concrete class
|
||||
if ( abstract_methods.__length === 0 )
|
||||
{
|
||||
return createConcreteCtor( cname, members );
|
||||
}
|
||||
// abstract class
|
||||
else
|
||||
{
|
||||
return createAbstractCtor( cname );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the constructor for a new concrete class
|
||||
*
|
||||
* This constructor will call the __constructor method of the class, if
|
||||
* available.
|
||||
*
|
||||
* @param {string} cname class name (may be empty)
|
||||
* @param {Object} members class members
|
||||
*
|
||||
* @return {function()} constructor
|
||||
*/
|
||||
function createConcreteCtor( cname, members )
|
||||
{
|
||||
var args = null;
|
||||
|
||||
// constructor function to be returned
|
||||
|
@ -246,10 +276,21 @@ exports.build = ( function( extending )
|
|||
;
|
||||
|
||||
return __self;
|
||||
}
|
||||
// abstract class
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the constructor for a new abstract class
|
||||
*
|
||||
* Calling this constructor will cause an exception to be thrown, as abstract
|
||||
* classes cannot be instantiated.
|
||||
*
|
||||
* @param {string} cname class name (may be empty)
|
||||
*
|
||||
* @return {function()} constructor
|
||||
*/
|
||||
function createAbstractCtor( cname )
|
||||
{
|
||||
var __abstract_self = function()
|
||||
{
|
||||
if ( !extending )
|
||||
|
@ -273,9 +314,7 @@ exports.build = ( function( extending )
|
|||
;
|
||||
|
||||
return __abstract_self;
|
||||
}
|
||||
}
|
||||
} )( false );
|
||||
}
|
||||
|
||||
|
||||
function buildMembers(
|
||||
|
|
Loading…
Reference in New Issue