From 5501f48570c6e225680232789c03270b64c1bf71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 1 Mar 2013 11:47:49 -0800 Subject: [PATCH] Move Item#toString() functionality to Base#toString(). For objects that define #_id and/or #_name. --- src/core/Base.js | 22 +++++++++++++--------- src/item/Item.js | 6 ------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/core/Base.js b/src/core/Base.js index 252c78e7..4df82497 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -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(', ') + ' }'; }, /** diff --git a/src/item/Item.js b/src/item/Item.js index 1268aca3..187f8384 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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