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

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

clojure - 'get' replacement that throws exception on not found? -