diff --git a/PRIMER.md b/PRIMER.md index 5a610d2fe3..0a01e42503 100644 --- a/PRIMER.md +++ b/PRIMER.md @@ -17,7 +17,7 @@ Below is a description of the current Polymer features, followed by individual f |---------|------- | [Custom element constructor](#element-constructor) | Polymer.Class({ … }); | [Custom element registration](#register-element) | Polymer({ is: ‘...’, … }}; -| [Bespoke constructor support](#bespoke-constructor) | constructor: function() { … } +| [Bespoke constructor support](#bespoke-constructor) | factoryImpl: function() { … } | [Basic lifecycle callbacks](#basic-callbacks) | created, attached, detached, attributeChanged | [Native HTML element extension](#type-extension) | extends: ‘…’ | [Configure properties](#property-config) | properties: { … } @@ -133,7 +133,7 @@ var el2 = document.createElement('my-element'); ## Bespoke constructor support -While the standard `Polymer.Class()` and `Polymer()` functions return a basic constructor that can be used to instance the custom element, Polymer also supports providing a bespoke `constructor` function on the prototype that can, for example, accept arguments to configure the element. In this case, the actual constructor returned from `Polymer` will first create an instance using `document.createElement`, then invoke the user-supplied `constructor` function with `this` bound to the element instance. +While the standard `Polymer.Class()` and `Polymer()` functions return a basic constructor that can be used to instance the custom element, Polymer also supports providing a `factoryImpl` function on the prototype that can, for example, accept arguments to configure the element. In this case, the actual constructor returned from `Polymer` will first create an instance using `document.createElement`, then invoke the user-supplied `factoryImpl` function with `this` bound to the element instance. Example: @@ -142,7 +142,7 @@ MyElement = Polymer({ is: 'my-element', - constructor: function(foo, bar) { + factoryImpl: function(foo, bar) { el.foo = foo; el.configureWithBar(bar); }, diff --git a/src/micro/constructor.html b/src/micro/constructor.html index e5809e2cde..e998544f73 100644 --- a/src/micro/constructor.html +++ b/src/micro/constructor.html @@ -40,10 +40,6 @@ // registration-time _prepConstructor: function() { - // capture user-supplied `constructor` - if (this.hasOwnProperty('constructor')) { - this._userConstructor = this.constructor; - } // support both possible `createElement` signatures this._factoryArgs = this.extends ? [this.extends, this.is] : [this.is]; // thunk the constructor to delegate allocation to `createElement` @@ -63,8 +59,8 @@ _factory: function(args) { var elt = document.createElement.apply(document, this._factoryArgs); - if (this._userConstructor) { - this._userConstructor.apply(elt, args); + if (this.factoryImpl) { + this.factoryImpl.apply(elt, args); } return elt; } diff --git a/test/unit/micro.html b/test/unit/micro.html index c967345f3f..56dbcc349f 100644 --- a/test/unit/micro.html +++ b/test/unit/micro.html @@ -69,7 +69,7 @@ test('custom constructor', function() { var MyElement2 = Polymer({ is: 'my-element2', - constructor: function(title){ + factoryImpl: function(title){ this.title = title; } });