javascript - Private non-static variables in polymer? -


how possible have private non-static variables in polymer?

in:

<polymer-element name="component-one">    <script>         polymer('component-one', {        internalstate = 1,            ready() {                this.anotherinternalstate = 1;            }            /* more variables , functions */       });     </script>  </polymer-element> 

both internalstate , anotherinernalstate exposed outside (e.g. accessible through like:

document.queryselector('component-one').internalstate 

(which might undesirable when changing internalstate outside makes component unstable.)

where in:

<polymer-element name="component-two">    <script>      (function() {          var internalstate = 1;          polymer('component-two', {           /* variables , functions */       });     })();     </script>  </polymer-element> 

internalstate hidden outside static , shared across instances of component.

is there way have private non-static variable inside polymer object?

this more of pure javascript question polymer question. of es5 there no 'private instance members' in javascript, although es6 brings new tools.

my suggestion use old convention of prepending private instance variables underscore (_internalstate).

otherwise, have tricky maps , closures.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -