Index: third_party/polymer/v0_8/components/polymer/src/micro/constructor.html |
diff --git a/third_party/polymer/v0_8/components/polymer/src/micro/constructor.html b/third_party/polymer/v0_8/components/polymer/src/micro/constructor.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e998544f73facd564f701474463f0533693b5b8e |
--- /dev/null |
+++ b/third_party/polymer/v0_8/components/polymer/src/micro/constructor.html |
@@ -0,0 +1,70 @@ |
+<!-- |
+@license |
+Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
+The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
+Code distributed by Google as part of the polymer project is also |
+subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
+--> |
+<script> |
+ |
+ /** |
+ * Generates a boilerplate constructor. |
+ * |
+ * XFoo = Polymer({ |
+ * is: 'x-foo' |
+ * }); |
+ * ASSERT(new XFoo() instanceof XFoo); |
+ * |
+ * You can supply a custom constructor on the prototype. But remember that |
+ * this constructor will only run if invoked **manually**. Elements created |
+ * via `document.createElement` or from HTML _will not invoke this method_. |
+ * |
+ * Instead, we reuse the concept of `constructor` for a factory method which |
+ * can take arguments. |
+ * |
+ * MyFoo = Polymer({ |
+ * is: 'my-foo', |
+ * constructor: function(foo) { |
+ * this.foo = foo; |
+ * } |
+ * ... |
+ * }); |
+ * |
+ * @class base feature: constructor |
+ */ |
+ |
+ Polymer.Base._addFeature({ |
+ |
+ // registration-time |
+ |
+ _prepConstructor: function() { |
+ // support both possible `createElement` signatures |
+ this._factoryArgs = this.extends ? [this.extends, this.is] : [this.is]; |
+ // thunk the constructor to delegate allocation to `createElement` |
+ var ctor = function() { |
+ return this._factory(arguments); |
+ }; |
+ if (this.hasOwnProperty('extends')) { |
+ ctor.extends = this.extends; |
+ } |
+ // ensure constructor is set. The `constructor` property is |
+ // not writable on Safari; note: Chrome requires the property |
+ // to be configurable. |
+ Object.defineProperty(this, 'constructor', {value: ctor, |
+ writable: true, configurable: true}); |
+ ctor.prototype = this; |
+ }, |
+ |
+ _factory: function(args) { |
+ var elt = document.createElement.apply(document, this._factoryArgs); |
+ if (this.factoryImpl) { |
+ this.factoryImpl.apply(elt, args); |
+ } |
+ return elt; |
+ } |
+ |
+ }); |
+ |
+</script> |