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
Post a Comment