accessing private properties in javascript object

Posted by Parvendra under JavaScript category on | Views : 1977
To access local variables create local functions within the scope of the constructor of main function

//define a function
function testpriv()
var local_var = 7;

this.GetPrivVar = function()
return local_var;

//make object of the function to initialize constructor
obj1 = new testpriv;

//access provate property by

//this line will give error saying 'local_var is not defined'

Comments or Responses

Login to post response