Getting into the Javascript prototype, I have no idea why when I call one prototype function from another and pass value to another, the value does not get updated.
Is that some problem related to closure? I tried to use global variable but still doesn't work. Any assistance?
function test(elem){
this.opt =
this.elem = $(elem)
this.method1();
}
test.prototype.method1 = function() {
var output = 1;
this.method2(output);
console.log(output);
}
test.prototype.method2 = function(output) {
output += 1;
}
var data = new test(this);
When I call method2 in method1 function, the output will not get updated, it will still console 1 as a result.