You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 29, 2019. It is now read-only.
Copy file name to clipboardExpand all lines: docs/polymer/polymer.md
+83-49
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,20 @@ At the heart of {{site.project_title}} are [Custom Elements](/platform/custom-el
20
20
<template>
21
21
<!-- shadow DOM here -->
22
22
</template>
23
-
<script>Polymer('tag-name');</script>
23
+
<script>
24
+
Polymer({
25
+
// properties and methods here
26
+
});
27
+
</script>
24
28
</polymer-element>
25
29
30
+
The element declaration includes:
31
+
32
+
- The `name` attribute specifies the name of the new custom element.
33
+
- The optional `<template>` tag defines HTML content that is
34
+
cloned into the shadow DOM of each instance of the element.
35
+
- The `Polymer` method, which _registers_ the element, so it's
36
+
recognized as a custom element by the browser.
26
37
27
38
### Attributes
28
39
@@ -42,7 +53,7 @@ At the heart of {{site.project_title}} are [Custom Elements](/platform/custom-el
42
53
<td><code>extends</code></td><td>optional</td><td>Used to <a href="#extending-other-elements">extend other elements</a>.</td>
43
54
</tr>
44
55
<tr>
45
-
<td><code>noscript</code></td><td>optional</td><td>For simple elements that don't need to call <code>Polymer()</code>. See <a href="#altregistration">Alternate ways to register an element</a>.</td>
56
+
<td><code>noscript</code></td><td>optional</td><td>For simple elements that don't need to call <code>Polymer()</code>. See <a href="#altregistration">Element registration</a>.</td>
46
57
</tr>
47
58
<tr>
48
59
<td><code>constructor</code></td><td>optional</td><td>The name of the constructor to put on the global object. Allows users to create instances of your element using the <code>new</code> operator (e.g. <code>var tagName = new TagName()</code>).</td>
@@ -56,7 +67,7 @@ on each instance of the element. For example:
Where both _tag-name_ and _proto-object_are optional. The _proto-object_ is used to define the element's `prototype`.
201
+
The _proto-object_contains properties and methods to add to the element's `prototype`.
169
202
170
203
The following example defines a property `message`, a property `greeting`
171
204
using an ES5 getter, and a method `foo`:
172
205
173
206
<polymer-element name="tag-name">
174
207
<template>{{greeting}}</template>
175
208
<script>
176
-
Polymer('tag-name', {
209
+
Polymer({
177
210
message: "Hello!",
178
211
get greeting() {
179
212
return this.message + ' there!';
@@ -196,6 +229,7 @@ Avoid defining a property or method with the same name as a native DOM property
196
229
`focus`, `title` and `hidden`; the results are unpredictable.
197
230
198
231
**Important:** Be careful when initializing properties that are objects or arrays. Due to the nature of `prototype`, you may run into unexpected "shared state" across instances of the same element. If you're initializing an array or object, do it in the `created` callback rather than directly on the `prototype`.
232
+
{: .alert .alert-error }
199
233
200
234
// Good!
201
235
Polymer('x-foo', {
@@ -220,11 +254,11 @@ techniques like anonymous self-calling functions:
220
254
<template>...</template>
221
255
<script>
222
256
(function() {
223
-
// Ran once. Private and static to the element.
257
+
// Run once. Private and static to the element.
224
258
var foo_ = new Foo();
225
259
226
-
// Ran for every instance of the element that's created.
227
-
Polymer('tag-name', {
260
+
// Run for every instance of the element that's created.
261
+
Polymer({
228
262
get foo() { return foo_; }
229
263
});
230
264
})();
@@ -245,7 +279,7 @@ To achieve this, you can use the [MonoState Pattern](http://c2.com/cgi/wiki?Mono
245
279
var firstName = 'John';
246
280
var lastName = 'Smith';
247
281
248
-
Polymer('app-globals', {
282
+
Polymer({
249
283
ready: function() {
250
284
this.firstName = firstName;
251
285
this.lastName = lastName;
@@ -264,7 +298,7 @@ Then use the element as you would any other, and data-bind it to a property that
0 commit comments