diff --git a/lib/straps.js b/lib/straps.js index ec487570..3e638b0b 100755 --- a/lib/straps.js +++ b/lib/straps.js @@ -252,16 +252,19 @@ var Base = this.Base = new function() { // Straps scope }, extend: function(src/* , ... */) { - var ctor = function() { - // Call the constructor function, if defined - if (this.initialize) - return this.initialize.apply(this, arguments); + var ctor, + base = this; + // Look for an initialize function in all injection scopes and use + // it as the actual constructor. + for (var i = 0, l = arguments.length; i < l; i++) + if (ctor = arguments[i].initialize) + break; + // If no initialize function is provided, create one that simply + // calls the base constructor. + ctor = ctor || function() { + base.apply(this, arguments); }; ctor.prototype = create(this.prototype); - // Add a toString function that delegates to initialize if possible - ctor.toString = function() { - return (this.prototype.initialize || function() {}).toString(); - }; // The new prototype extends the constructor on which extend is // called. Fix constructor. define(ctor.prototype, 'constructor', diff --git a/src/item/Group.js b/src/item/Group.js index 6e42c04f..f7558d09 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -89,7 +89,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{ * }); */ initialize: function(arg) { - this.base(); + Item.call(this); // Allow Group to have children and named children this._children = []; this._namedChildren = {}; diff --git a/src/item/Layer.js b/src/item/Layer.js index ff2afaf0..8d60f91a 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -61,7 +61,7 @@ var Layer = this.Layer = Group.extend(/** @lends Layer# */{ this._project = paper.project; // Push it onto project.layers and set index: this._index = this._project.layers.push(this) - 1; - this.base.apply(this, arguments); + Group.apply(this, arguments); this.activate(); }, diff --git a/src/item/PlacedSymbol.js b/src/item/PlacedSymbol.js index 06298ac2..a7766752 100644 --- a/src/item/PlacedSymbol.js +++ b/src/item/PlacedSymbol.js @@ -72,7 +72,7 @@ var PlacedSymbol = this.PlacedSymbol = Item.extend(/** @lends PlacedSymbol# */{ // Support two forms of item initialization: Passing one object literal // describing all the different properties to be set, or a symbol (arg0) // and a point where it should be placed (arg1). - this.base(arg1 !== undefined && Point.read(arguments, 1)); + Item.call(this, arg1 !== undefined && Point.read(arguments, 1)); // If we can handle setting properties through object literal, we're all // set. Otherwise we need to set symbol. if (arg0 && !this._set(arg0)) diff --git a/src/item/Raster.js b/src/item/Raster.js index 5899222f..3ce86c6f 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -76,7 +76,7 @@ var Raster = this.Raster = Item.extend(/** @lends Raster# */{ // Support two forms of item initialization: Passing one object literal // describing all the different properties to be set, or an image // (object) and a point where it should be placed (point). - this.base(position !== undefined && Point.read(arguments, 1)); + Item.call(this, position !== undefined && Point.read(arguments, 1)); // If we can handle setting properties through object literal, we're all // set. Otherwise we need to check the type of object: if (object && !this._set(object)) { diff --git a/src/item/Shape.js b/src/item/Shape.js index 3a11335f..4320a82d 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -22,7 +22,7 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{ _applyMatrix: false, initialize: function(type, point, size) { - this.base(point); + Item.call(this, point); this._type = type; this._size = size; }, diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 9cf5a976..a35313a2 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -50,7 +50,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend(/** @lends CompoundPath# * compoundPath.children[1].position.x += 5; */ initialize: function(arg) { - this.base(); + PathItem.call(this); // CompoundPath has children and supports named children. this._children = []; this._namedChildren = {}; diff --git a/src/path/Path.js b/src/path/Path.js index e844e3a6..4850eb24 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -70,7 +70,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{ initialize: function(arg) { this._closed = false; this._segments = []; - this.base(); + Item.call(this); // arg can either be an object literal describing properties to be set // on the path, a list of segments to be set, or the first of multiple // arguments describing separate segments. diff --git a/src/project/Project.js b/src/project/Project.js index 5f71d2fa..bd1c1e5b 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -47,7 +47,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{ initialize: function(view) { // Activate straight away by passing true to base(), so paper.project is // set, as required by Layer and DoumentView constructors. - this.base(true); + PaperScopeItem.call(this, true); this.layers = []; this.symbols = []; this._currentStyle = new Style(); diff --git a/src/text/TextItem.js b/src/text/TextItem.js index 91986253..81f132e3 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -38,7 +38,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{ // might be a properties object literal for #setPropeties() at the end. var hasProperties = arg && Base.isPlainObject(arg) && arg.x === undefined && arg.y === undefined; - this.base(hasProperties ? null : Point.read(arguments)); + Item.call(this, hasProperties ? null : Point.read(arguments)); this._content = ''; this._lines = []; if (hasProperties) diff --git a/src/tool/Tool.js b/src/tool/Tool.js index fbdc2dfb..8f227150 100644 --- a/src/tool/Tool.js +++ b/src/tool/Tool.js @@ -51,7 +51,7 @@ var Tool = this.Tool = PaperScopeItem.extend(/** @lends Tool# */{ // DOCS: rewrite Tool constructor explanation initialize: function(props) { - this.base(); + PaperScopeItem.call(this); this._firstMove = true; this._count = 0; this._downCount = 0; diff --git a/src/ui/CanvasView.js b/src/ui/CanvasView.js index 077f2b1e..c523dfe5 100644 --- a/src/ui/CanvasView.js +++ b/src/ui/CanvasView.js @@ -34,7 +34,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ this._context = canvas.getContext('2d'); // Have Item count installed mouse events. this._eventCounters = {}; - this.base(canvas); + View.call(this, canvas); }, /** diff --git a/src/ui/KeyEvent.js b/src/ui/KeyEvent.js index c1dcecec..9b80e540 100644 --- a/src/ui/KeyEvent.js +++ b/src/ui/KeyEvent.js @@ -22,7 +22,7 @@ */ var KeyEvent = this.KeyEvent = Event.extend(/** @lends KeyEvent# */{ initialize: function(down, key, character, event) { - this.base(event); + Event.call(this, event); this.type = down ? 'keydown' : 'keyup'; this.key = key; this.character = character; diff --git a/src/ui/MouseEvent.js b/src/ui/MouseEvent.js index a520e51b..7727ee3f 100644 --- a/src/ui/MouseEvent.js +++ b/src/ui/MouseEvent.js @@ -24,7 +24,7 @@ */ var MouseEvent = this.MouseEvent = Event.extend(/** @lends MouseEvent# */{ initialize: function(type, event, point, target, delta) { - this.base(event); + Event.call(this, event); this.type = type; this.point = point; this.target = target;