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
|
* Instance id counter, to be incremented on each new instance
|
||||||
* @type {number}
|
* @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,8 +80,6 @@ var enum_bug = (
|
||||||
exports.ClassBase = function Class() {};
|
exports.ClassBase = function Class() {};
|
||||||
|
|
||||||
|
|
||||||
exports.build = ( function( extending )
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Mimics class inheritance
|
* Mimics class inheritance
|
||||||
*
|
*
|
||||||
|
@ -85,7 +92,7 @@ exports.build = ( function( extending )
|
||||||
*
|
*
|
||||||
* @return {Object} extended class
|
* @return {Object} extended class
|
||||||
*/
|
*/
|
||||||
return function extend()
|
exports.build = function extend()
|
||||||
{
|
{
|
||||||
// ensure we'll be permitted to instantiate abstract classes for the base
|
// ensure we'll be permitted to instantiate abstract classes for the base
|
||||||
extending = true;
|
extending = true;
|
||||||
|
@ -181,6 +188,29 @@ exports.build = ( function( extending )
|
||||||
{
|
{
|
||||||
// concrete class
|
// concrete class
|
||||||
if ( abstract_methods.__length === 0 )
|
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;
|
var args = null;
|
||||||
|
|
||||||
|
@ -247,8 +277,19 @@ exports.build = ( function( extending )
|
||||||
|
|
||||||
return __self;
|
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()
|
var __abstract_self = function()
|
||||||
{
|
{
|
||||||
|
@ -274,8 +315,6 @@ exports.build = ( function( extending )
|
||||||
|
|
||||||
return __abstract_self;
|
return __abstract_self;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} )( false );
|
|
||||||
|
|
||||||
|
|
||||||
function buildMembers(
|
function buildMembers(
|
||||||
|
|
Loading…
Reference in New Issue