From a30e4057e38a5c6eae28caa56bf10f86fdeb579d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 13 Feb 2011 15:39:24 +0000 Subject: [PATCH] Fix PathItem constructor to support passing of segments both as array and arguments. --- src/path/PathItem.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/path/PathItem.js b/src/path/PathItem.js index f6149dcf..4a0f140a 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -38,15 +38,22 @@ PathItem = Item.extend(new function() { return { beans: true, - initialize: function() { + initialize: function(segments) { this.base(); this.closed = false; - this._segments = [];//new SegmentList(this); + this._segments = []; this.bounds = new Rectangle(); - for(var i = 0, l = arguments.length; i < l; i++) { - var segment = new Segment(arguments[i]); - this.addSegment(segment); - } + // Support both passing of segments as array or arguments + // TODO: Use better isArray check, i.e. the one from + // http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ + // Or rely on Base.type()? in Bootstrap? + // If it is an array, it can also be a description of a point, so + // check its first entry for object as well + if (!segments || segments.length === undefined + || typeof segments[0] != 'object') + segments = arguments; + for(var i = 0, l = segments.length; i < l; i++) + this.addSegment(new Segment(segments[i])); }, /**