class - Javascript: Revealing Module Pattern. Access private members -


i have javascript library exposing members using 'revealing module pattern'. have particular need need access private member. can me on regard? tips , tricks? highly appreciate if can shed light on this. in advance.

revealing module pattern addy osmani

var myrevealingmodule = (function () {      var privatevar = "ben cherry",         publicvar = "hey there!";      function privatefunction() {         console.log( "name: " + privatevar );     }      function publicsetname( strname ) {         privatevar = strname;     }      function publicgetname() {         privatefunction();     }       // reveal public pointers     // private functions , properties      return {         setname: publicsetname,         greeting: publicvar,         getname: publicgetname     };  })();  myrevealingmodule.setname( "paul kinlan" ); myrevealingmodule.getname();  // there anyway access 'privatefunction'???? 

is there anyway access 'privatefunction'????

any tips , tricks? highly appreciate if can shed light on this. in advance.

you create object of myrevealingmodule, contains setname, greeting, , getname. these, setname references publicsetname , getname references publicgetname. on turn, publicgetname need: calls privatefunction.

so, answer question:

myrevealingmodule.publicgetname(); 

is how access privatefunction. can change value of privatevar way:

myrevealingmodule.publicsetname("foobar"); myrevealingmodule.publicgetname(); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -