Move Item#toString() functionality to Base#toString().

For objects that define #_id and/or #_name.
This commit is contained in:
Jürg Lehni 2013-03-01 11:47:49 -08:00
parent bec61c6829
commit 5501f48570
2 changed files with 13 additions and 15 deletions

View file

@ -35,15 +35,19 @@ this.Base = Base.inject(/** @lends Base# */{
* Renders base objects to strings in object literal notation.
*/
toString: function() {
return '{ ' + Base.each(this, function(value, key) {
// Hide internal properties even if they are enumerable
if (!/^_/.test(key)) {
var type = typeof value;
this.push(key + ': ' + (type === 'number'
? Format.number(value)
: type === 'string' ? "'" + value + "'" : value));
}
}, []).join(', ') + ' }';
return this._id != null
? (this.constructor._name || 'Object') + (this._name
? " '" + this._name + "'"
: ' @' + this._id)
: '{ ' + Base.each(this, function(value, key) {
// Hide internal properties even if they are enumerable
if (!/^_/.test(key)) {
var type = typeof value;
this.push(key + ': ' + (type === 'number'
? Format.number(value)
: type === 'string' ? "'" + value + "'" : value));
}
}, []).join(', ') + ' }';
},
/**

View file

@ -2058,12 +2058,6 @@ var Item = this.Item = Base.extend(Callback, {
this.setBounds(newBounds);
},
toString: function() {
return (this.constructor._name || 'Item') + (this._name
? " '" + this._name + "'"
: ' @' + this._id);
},
// DOCS: document exportJson (documented in @private Base)
// DOCS: document importJson
// DOCS: Figure out a way to group these together with importSvg / exportSvg