Moved attachId() to class_builder
parent
55288f1e07
commit
f43959640c
35
lib/class.js
35
lib/class.js
|
@ -353,14 +353,10 @@ function createImplement( base, ifaces, cname )
|
|||
function extend()
|
||||
{
|
||||
// set up the new class
|
||||
var data = class_builder.build.apply( null, arguments ),
|
||||
var new_class = class_builder.build.apply( null, arguments );
|
||||
|
||||
new_class = data[ 'class' ],
|
||||
class_id = data.classId
|
||||
;
|
||||
|
||||
// important: call after setting prototype
|
||||
setupProps( new_class, class_id );
|
||||
// set up some additional convenience props
|
||||
setupProps( new_class );
|
||||
|
||||
// lock down the new class (if supported) to ensure that we can't add
|
||||
// members at runtime
|
||||
|
@ -418,16 +414,14 @@ var implement = function()
|
|||
/**
|
||||
* Sets up common properties for the provided function (class)
|
||||
*
|
||||
* @param {function()} func function (class) to set up
|
||||
* @param {number} class_id unique id to assign to class
|
||||
* @param {function()} func function (class) to set up
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function setupProps( func, class_id )
|
||||
function setupProps( func )
|
||||
{
|
||||
attachExtend( func );
|
||||
attachImplement( func );
|
||||
attachId( func, class_id );
|
||||
}
|
||||
|
||||
|
||||
|
@ -477,22 +471,3 @@ function attachImplement( func )
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attaches the unique id to the class and its prototype
|
||||
*
|
||||
* The unique identifier is used internally to match a class and its instances
|
||||
* with the class metadata. Exposing the id breaks encapsulation to a degree,
|
||||
* but is a lesser evil when compared to exposing all metadata.
|
||||
*
|
||||
* @param {Function} func function (class) to attach method to
|
||||
* @param {number} id id to assign
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function attachId( func, id )
|
||||
{
|
||||
util.defineSecureProp( func, '__cid', id );
|
||||
util.defineSecureProp( func.prototype, '__cid', id );
|
||||
}
|
||||
|
||||
|
|
|
@ -217,14 +217,12 @@ exports.build = function extend()
|
|||
meta.name = cname;
|
||||
|
||||
attachAbstract( new_class, abstract_methods );
|
||||
attachId( new_class, class_id );
|
||||
|
||||
// we're done with the extension process
|
||||
extending = false;
|
||||
|
||||
return {
|
||||
'class': new_class,
|
||||
classId: class_id,
|
||||
};
|
||||
return new_class;
|
||||
};
|
||||
|
||||
|
||||
|
@ -752,3 +750,22 @@ function attachAbstract( func, methods )
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attaches the unique id to the class and its prototype
|
||||
*
|
||||
* The unique identifier is used internally to match a class and its instances
|
||||
* with the class metadata. Exposing the id breaks encapsulation to a degree,
|
||||
* but is a lesser evil when compared to exposing all metadata.
|
||||
*
|
||||
* @param {function()} ctor constructor (class) to attach method to
|
||||
* @param {number} id id to assign
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
function attachId( ctor, id )
|
||||
{
|
||||
util.defineSecureProp( ctor, '__cid', id );
|
||||
util.defineSecureProp( ctor.prototype, '__cid', id );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue