string1 and string2 are the same, string1 uses a compact syntax available
if you want only to express type. Neither property is ever assigned any
value, so they are not visible as properties (hasOwnProperty is false).

string3 is the same as 1 and 2, except for being initialized to '' at
create-time. Because it's assigned a value, it's now visible as an
own-property.

string4 will reflectToAttribute if it is assigned a value, but since it
never is assigned a value, it never reflects and no attribute is created.
Because the property has a side-effect (reflection) it's prepared as
accessor pair (getter/setter) on the element _prototype_ so it can be
observed. For this reason, it's not an own-property.

string5 is just like string4, except it's assigned the value '' at
create-time, and consequently reflects that value to it's attribute.

Also, fwiw, in all cases `type: String` can be omitted, since this is the
default.

Much of this behavior is explained by the simple principle that Polymer
strives to do as little work as possible, to optimize performance.

HTH,
Scott


On Tue, May 12, 2015 at 12:43 AM, <[email protected]> wrote:

> I'm confused about properties. Is there precise documentation about how
> different ways of declaring properties affects the created elements?
>
> If I have this properties block:
>
> properties: {
>   string1: String,
>
>   string2: {
>     type: String
>   },
>
>   string3:{
>     type: String,
>     value: ''
>   },
>
>   string4: {
>     type: String,
>     reflectToAttribute: true,
>   },
>
>   string5: {
>     type: String,
>     value: '',
>     reflectToAttribute: true
>   }
> }
>
> It seems an instance of my element will only have one attribute:
> <element string5="">.
>
> Furthermore:
> element.hasOwnProperty('string1') === false;
> element.hasOwnProperty('string2') === false;
> element.hasOwnProperty('string3') === true; element.string3 === '';
> element.hasOwnProperty('string4') === true; element.string4 === undefined;
> element.hasOwnProperty('string5') === true; element.string5 === '';
>
> The behavior of element.string4 is particularly baffling.
>
> Follow Polymer on Google+: plus.google.com/107187849809354688692
> ---
> You received this message because you are subscribed to the Google Groups
> "Polymer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/polymer-dev/aa1f40ef-dadf-4aaf-abbc-e97a5074d5c3%40googlegroups.com
> <https://groups.google.com/d/msgid/polymer-dev/aa1f40ef-dadf-4aaf-abbc-e97a5074d5c3%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

Follow Polymer on Google+: plus.google.com/107187849809354688692
--- 
You received this message because you are subscribed to the Google Groups 
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/CAHbmOLb-hwWxpkYjb8ZLUg8SR7RzJBy5tm9sNzr9uMoC3G_-WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to