Skip to content

Commit

Permalink
Add toString to Constructor. Closes #83
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Feb 22, 2013
1 parent 375eee7 commit bdd66ab
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/component/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
define([ "troopjs-utils/unique", "poly/object" ], function ComponentFactoryModule(unique) {
/*jshint laxbreak:true */

var ARRAY_PROTO = Array.prototype;
var PROTOTYPE = "prototype";
var TOSTRING = "toString";
var ARRAY_PROTO = Array[PROTOTYPE];
var ARRAY_PUSH = ARRAY_PROTO.push;
var ARRAY_UNSHIFT = ARRAY_PROTO.unshift;
var OBJECT_TOSTRING = Object[PROTOTYPE][TOSTRING];
var TYPEOF_FUNCTION = typeof function () {};
var PROTOTYPE = "prototype";
var DISPLAYNAME = "displayName";
var LENGTH = "length";
var EXTEND = "extend";
var CREATE = "create";
Expand Down Expand Up @@ -151,6 +154,19 @@ define([ "troopjs-utils/unique", "poly/object" ], function ComponentFactoryModul
return descriptor;
};

/**
* Returns a string representation of this constructor
* @returns {String}
*/
function ConstructorToString() {
var self = this;
var prototype = self[PROTOTYPE];

return DISPLAYNAME in prototype
? prototype[DISPLAYNAME]
: OBJECT_TOSTRING.call(self);
}

/**
* Creates components
* @returns {*} New component
Expand Down Expand Up @@ -328,6 +344,10 @@ define([ "troopjs-utils/unique", "poly/object" ], function ComponentFactoryModul
"value" : specials
};

constructorDescriptors[TOSTRING] = {
"value" : ConstructorToString
};

// Add EXTEND to constructorDescriptors
constructorDescriptors[EXTEND] = {
"value" : extend
Expand Down

0 comments on commit bdd66ab

Please # to comment.