private instance functions and properties

506 views
Skip to first unread message

Max Waterman

unread,
Oct 6, 2014, 12:38:20 PM10/6/14
to polym...@googlegroups.com
(advised by Mr Dodson to post this question here rather than on G+)

I see[0] how to make private static functions and properties - they're common to all instances of the element - but how to make private instance functions and properties so we can store state outside the prototype?

Any ideas?

Thanks,

Max.

Arthur Evans

unread,
Oct 6, 2014, 4:12:24 PM10/6/14
to Max Waterman, polymer-dev
Hi Max,

Yes, the title of the section "Adding private or static variables" is confusing, since it only shows variables that 
are both static AND private.


If you want to store state outside of the prototype, you can add properties on this, as you would with any JavaScript object. A good time to do this is in the created callback. This is discussed in the context of published properties, here:


This jsbin: 


Shows a private instance variable, exposed via a (published) getter and setter.

Note that in this example, I'm binding to the published name, foo. If the property wasn't published, I'd need to bind to the private name, foo_. I'm not sure whether data binding is relevant to your use case -- I'm only using it here to demonstrate that each instance has its own foo_ value.

Hope this helps,
Arthur


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 polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/2a7b2405-436e-4798-9357-b7dd3dcf8bb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages