I have a question about this fonction:
var MyObject3 = function (a, b) {
var obj = { myA : a, myB : b } ;
obj.foo = function () { return obj.myA + obj.myB ; } ;
obj.bar = function (c) { return obj.myA + c ; } ;
return obj ;
} ;
obj.foo and obj.bar are closures(what i understand). I write first:
obj3 = MyObject3(1, 2) ;
and the result is: {"myA" :1,"myB" :2}. This is OK. I try to change the value of obj3.myA : > obj3.myA = 4 ; obj3 ; and the result is : {"myA" :4,"myB" :2} . What I don't understand is: why > obj3.foo() ; returns 6? obj3.foo() gives 6 as a result ? obj3.foo() is supposed to be a closure isn'it ? its result should be;3 ?