title: Javascript Closure code
body: <p>I have a question about this fonction:</p>
  
  <pre><code>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 ;
  } ;
  </code></pre>
  
  <p>obj.foo and obj.bar are closures(what i understand). I write first: </p>
  
  <pre><code> obj3 = MyObject3(1, 2) ;
  </code></pre>
  
  <p>and the result is: <code>{"myA" :1,"myB" :2}</code>. This is OK.  I try to change the value of obj3.myA : > obj3.myA = 4 ; obj3 ; and the result is : <code>{"myA" :4,"myB" :2}</code> . What I don't understand is: why <code>&gt; obj3.foo() ;</code> returns 6? obj3.foo() gives 6 as a result ? obj3.foo() is supposed to be a closure isn'it ? its result should be;3 ?</p>