I have written a code to get and set local variable in a javascript function; it's not working.
function wrapper() {
var x = 10;
this.getX = function () {
return x; //Return x
}
this.setX = function (newX) {
x = newX; //Set value for x
}
}
var obj = wrapper();
obj.getX(); //Get value of x in wrapper
obj.setX(25); //Set value of x in wrapper
How to get and set local variables in javascript function from external code.