From 26b70309a81dc46db14b0452da657681c771d1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 2 May 2011 08:57:55 +0100 Subject: [PATCH] Improve various #toString() functions. --- src/color/Color.js | 6 +++--- src/path/Curve.js | 14 +++++++------- src/path/CurveLocation.js | 2 +- src/path/Segment.js | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/color/Color.js b/src/color/Color.js index b8b53d1b..4d551037 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -173,15 +173,15 @@ var Color = this.Color = Base.extend(new function() { }, toString: function() { - var string = ''; + var parts = []; for (var i = 0, l = this._components.length; i < l; i++) { var component = this._components[i]; var value = this['_' + component]; if (component === 'alpha' && value == null) value = 1; - string += (i > 0 ? ', ' : '') + component + ': ' + value; + parts.push(component + ': ' + value); } - return '{ ' + string + ' }'; + return '{ ' + parts.join(', ') + ' }'; }, toCssString: function() { diff --git a/src/path/Curve.js b/src/path/Curve.js index 4f34cdee..ec9b240c 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -216,13 +216,13 @@ var Curve = this.Curve = Base.extend({ }, toString: function() { - return '{ point1: ' + this._segment1._point - + (!this._segment1._handleOut.isZero() - ? ', handle1: ' + this._segment1._handleOut : '') - + (this._segment2._handleIn.isZero() - ? ', handle2: ' + this._segment2._handleIn : '') - + ', point2: ' + this._segment2._point - + ' }'; + var parts = [ 'point1: ' + this._segment1._point ]; + if (!this._segment1._handleOut.isZero()) + parts.push('handle1: ' + this._segment1._handleOut); + if (!this._segment2._handleIn.isZero()) + parts.push('handle2: ' + this._segment2._handleIn); + parts.push('point2: ' + this._segment2._point); + return '{ ' + parts.join(', ') + ' }'; }, statics: { diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index adb17b69..54d8f5fa 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -139,6 +139,6 @@ CurveLocation = Base.extend({ var parameter = this.getParameter(); if (parameter != null) parts.push('parameter: ' + parameter); - return '{ ' + parts.join(', ') + ' }' + return '{ ' + parts.join(', ') + ' }'; } }); diff --git a/src/path/Segment.js b/src/path/Segment.js index d2d77567..ab90b275 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -230,12 +230,12 @@ var Segment = this.Segment = Base.extend({ }, toString: function() { - return '{ point: ' + this._point - + (!this._handleIn.isZero() - ? ', handleIn: ' + this._handleIn : '') - + (this._handleOut.isZero() - ? ', handleOut: ' + this._handleOut : '') - + ' }'; + var parts = [ 'point: ' + this._point ]; + if (!this._handleIn.isZero()) + parts.push('handleIn: ' + this._handleIn); + if (!this._handleOut.isZero()) + parts.push('handleOut: ' + this._handleOut); + return '{ ' + parts.join(', ') + ' }'; }, _transformCoordinates: function(matrix, coords, change) {