Moved attachId() to class_builder
parent
55288f1e07
commit
f43959640c
33
lib/class.js
33
lib/class.js
|
@ -353,14 +353,10 @@ function createImplement( base, ifaces, cname )
|
||||||
function extend()
|
function extend()
|
||||||
{
|
{
|
||||||
// set up the new class
|
// 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' ],
|
// set up some additional convenience props
|
||||||
class_id = data.classId
|
setupProps( new_class );
|
||||||
;
|
|
||||||
|
|
||||||
// important: call after setting prototype
|
|
||||||
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,15 +415,13 @@ 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 {number} class_id unique id to assign to class
|
|
||||||
*
|
*
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
function setupProps( func, class_id )
|
function setupProps( func )
|
||||||
{
|
{
|
||||||
attachExtend( func );
|
attachExtend( func );
|
||||||
attachImplement( 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;
|
meta.name = cname;
|
||||||
|
|
||||||
attachAbstract( new_class, abstract_methods );
|
attachAbstract( new_class, abstract_methods );
|
||||||
|
attachId( new_class, class_id );
|
||||||
|
|
||||||
// we're done with the extension process
|
// we're done with the extension process
|
||||||
extending = false;
|
extending = false;
|
||||||
|
|
||||||
return {
|
return new_class;
|
||||||
'class': new_class,
|
|
||||||
classId: class_id,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -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