Improve various #toString() functions.

This commit is contained in:
Jürg Lehni 2011-05-02 08:57:55 +01:00
parent 0a4150a5c9
commit 26b70309a8
4 changed files with 17 additions and 17 deletions

View file

@ -173,15 +173,15 @@ var Color = this.Color = Base.extend(new function() {
}, },
toString: function() { toString: function() {
var string = ''; var parts = [];
for (var i = 0, l = this._components.length; i < l; i++) { for (var i = 0, l = this._components.length; i < l; i++) {
var component = this._components[i]; var component = this._components[i];
var value = this['_' + component]; var value = this['_' + component];
if (component === 'alpha' && value == null) if (component === 'alpha' && value == null)
value = 1; value = 1;
string += (i > 0 ? ', ' : '') + component + ': ' + value; parts.push(component + ': ' + value);
} }
return '{ ' + string + ' }'; return '{ ' + parts.join(', ') + ' }';
}, },
toCssString: function() { toCssString: function() {

View file

@ -216,13 +216,13 @@ var Curve = this.Curve = Base.extend({
}, },
toString: function() { toString: function() {
return '{ point1: ' + this._segment1._point var parts = [ 'point1: ' + this._segment1._point ];
+ (!this._segment1._handleOut.isZero() if (!this._segment1._handleOut.isZero())
? ', handle1: ' + this._segment1._handleOut : '') parts.push('handle1: ' + this._segment1._handleOut);
+ (this._segment2._handleIn.isZero() if (!this._segment2._handleIn.isZero())
? ', handle2: ' + this._segment2._handleIn : '') parts.push('handle2: ' + this._segment2._handleIn);
+ ', point2: ' + this._segment2._point parts.push('point2: ' + this._segment2._point);
+ ' }'; return '{ ' + parts.join(', ') + ' }';
}, },
statics: { statics: {

View file

@ -139,6 +139,6 @@ CurveLocation = Base.extend({
var parameter = this.getParameter(); var parameter = this.getParameter();
if (parameter != null) if (parameter != null)
parts.push('parameter: ' + parameter); parts.push('parameter: ' + parameter);
return '{ ' + parts.join(', ') + ' }' return '{ ' + parts.join(', ') + ' }';
} }
}); });

View file

@ -230,12 +230,12 @@ var Segment = this.Segment = Base.extend({
}, },
toString: function() { toString: function() {
return '{ point: ' + this._point var parts = [ 'point: ' + this._point ];
+ (!this._handleIn.isZero() if (!this._handleIn.isZero())
? ', handleIn: ' + this._handleIn : '') parts.push('handleIn: ' + this._handleIn);
+ (this._handleOut.isZero() if (!this._handleOut.isZero())
? ', handleOut: ' + this._handleOut : '') parts.push('handleOut: ' + this._handleOut);
+ ' }'; return '{ ' + parts.join(', ') + ' }';
}, },
_transformCoordinates: function(matrix, coords, change) { _transformCoordinates: function(matrix, coords, change) {