javascript - Calling private methods -


i'm following blog , playing code.

function myclass() {   var self = this;   var privatevar = 'my private variable';   this.publicvar = 'my public variable';   var privatefunction = function () {     self.publicvar += ' modified private fucntion';     alert(self.publicvar);   };   privatefunction(); //1:  why code not working. kindly give reason this. } 

how might can call privatefunction ?? output looking // "my private variable modified private fucntion"

this code should work. not instantiating myclass anywhere.

function myclass() { var self = this; var privatevar = 'my private variable'; this.publicvar = 'my public variable'; var privatefunction = function () {   self.publicvar += ' modified private fucntion';   alert(self.publicvar); }; privatefunction(); // why code not working.. }; new myclass(); //run myclass, triggering code. 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -