(almost) Always Have Polymer Definition Inside A Closure?
Solution 1:
This is completely up to you as the element designer. Variables in the closure will be as private
as it gets in JavaScript. Properties on the prototype are generally hackable.
One camp values isolation, and prefers privatizing as much as possible to prevent errors and improve upgrade-ability.
Another camp values open APIs, and prefers allowing the developer access, in order to solve problems the author didn't envision.
You get to decide which camp you are in (or invent a new one =P).
Solution 2:
No! There is one major problem with above code. Since privateObj is sealed by the closure, it is static (e.g. shared among all the instances of that component) and cannot keep the state for each of them.
Moreover the idea is that the state of each component solely be determined by its attributes so keeping an internal state object should be avoided.
Post a Comment for "(almost) Always Have Polymer Definition Inside A Closure?"