1
0
Fork 0

Chose a more tolerable name to show in debuggers for class instances

closure/master
Mike Gerwitz 2011-03-29 22:04:54 -04:00
parent 5cb0b8355f
commit 08771b2b97
1 changed files with 9 additions and 7 deletions

View File

@ -268,19 +268,21 @@ function createConcreteCtor( cname, members )
{ {
var args = null; var args = null;
// constructor function to be returned // constructor function to be returned (the name is set to ClassInstance
var __self = function() // because some debuggers (e.g. v8) will show the name of this function for
// constructor instances rather than invoking the toString() method)
var ClassInstance = function ClassInstance()
{ {
if ( !( this instanceof __self ) ) if ( !( this instanceof ClassInstance ) )
{ {
// store arguments to be passed to constructor and // store arguments to be passed to constructor and
// instantiate new object // instantiate new object
args = arguments; args = arguments;
return new __self(); return new ClassInstance();
} }
// generate and store unique instance id // generate and store unique instance id
attachInstanceId( this, ++instance_id, __self ); attachInstanceId( this, ++instance_id, ClassInstance );
initInstance( instance_id, this ); initInstance( instance_id, this );
this.__initProps(); this.__initProps();
@ -324,12 +326,12 @@ function createConcreteCtor( cname, members )
}; };
// provide a more intuitive string representation // provide a more intuitive string representation
__self.toString = ( cname ) ClassInstance.toString = ( cname )
? function() { return cname; } ? function() { return cname; }
: function() { return '(Class)'; } : function() { return '(Class)'; }
; ;
return __self; return ClassInstance;
} }