On Sun, Oct 23, 2016 at 10:12 PM, Daniel Llewellyn <[email protected]> wrote:
> > > On Sun, 23 Oct 2016 at 20:59 Toni <[email protected]> wrote: > >> 1. By default, properties of Polymer objects are shared across all >> instances of the object (or, to be more precise, all references to the >> object, since Polymer doesn't create new instances, as in "new Element()"). >> Basically, all properties are by default static. >> > > This is not quite accurate. > > >> 2. Every property that is supposed to be individual to the specific >> reference, in other words, be not static, and changable without messing >> with any other instance/reference, has to have the field "value: function() >> { return []; }". >> > > This is only required for Arrays and Objects. > > Explanation: > > In Javascript all variables are passed-by-value. The variable "holding" an > Object doesn't actually hold the Object; it only holds a reference to the > Object in memory. Whereas a variable pertaining to a primitive type > actually holds the value rather than a reference to the value in memory. > > When Polymer creates a new instance of your element it copies the > prototype into a new Object. When the variable is copied the value is > copied and passed-by-value but as the value is actually a reference to the > original Object then the new instance will use the same object as all other > instances. > .. making it (somewhat) possible to make e.g. behaviors that act like a (singleton) service - like in angular. As long as you don't reassign any full object/array to the ones that should live a shared life. > > This is a problem with Javascript in general and not specific to Polymer. > ..or "the quirks of javascript came to the rescue as polymer doesn't have other (known to me at least :)) ways of replicating angular (singleton) services" :) - Lars > > Dan. > > Follow Polymer on Google+: plus.google.com/107187849809354688692 > --- > You received this message because you are subscribed to a topic in the > Google Groups "Polymer" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/polymer-dev/pa_Ak2ATRw8/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/polymer-dev/CABtuYwfLtupeCsgP-NVxoXbHEC2Yqna9% > 3DyfRuqCXxQRjGKVgXQ%40mail.gmail.com > <https://groups.google.com/d/msgid/polymer-dev/CABtuYwfLtupeCsgP-NVxoXbHEC2Yqna9%3DyfRuqCXxQRjGKVgXQ%40mail.gmail.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/CA%2Bjkkcg_JpVtVCycB4PMjFCnPrxvnLf5-xV9YiYyf4eH1z0F%3Dg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
