I created the following javascript object.
var obj = function () {
var a = 6;
var b = 7;
var sumFunction;
function sum() {
alert(a);
alert(b);
sumFunction();
}
return {
a: a,
b: b,
sum: function (f) {
sumFunction = f;
sum();
}
}
}
var o = new obj;
function Calculate() {
o.a = 3;
o.b = 4;
o.sum(function () {
alert('finish');
});
}
When the Calculate method is called, the two alert box show 6 and 7. It should be 3 and 4. I don't know what wrong my object. How can I correct this? Thanks.
this. it should bethis.a, andthis.b