mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Move Item#toString() functionality to Base#toString().
For objects that define #_id and/or #_name.
This commit is contained in:
parent
bec61c6829
commit
5501f48570
2 changed files with 13 additions and 15 deletions
|
@ -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(', ') + ' }';
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue