title: "this" in function invocation javascript
body: <pre><code>// Situation 1 
  var a = function A() { 
      this.x = 1;
      var b = function B () {
          this.x = 2;
          console.log('Method B : x = ' + this.x);
      };
      console.log('Method A : x = ' + this.x);
      b();
  }
  </code></pre>
  
  <p>When I call a() , my result is </p>
  
  <pre><code>Method A : x = 1
  Method B : x = 2
  </code></pre>
  
  <p>But if I delete "this.x = 2" as :</p>
  
  <pre><code>// Situation 2
  var a = function A() { 
      this.x = 1;
      var b = function B () {
          console.log('Method B : x = ' + this.x);
      };
      console.log('Method A : x = ' + this.x);
      b();
  }
  </code></pre>
  
  <p>My result will be </p>
  
  <pre><code>Method A : x = 1
  Method B : x = 1
  </code></pre>
  
  <p>I don't understand why </p>
  
  <ul>
  <li>In situation 2 : "this" of function B is referenced to "this" of function A </li>
  </ul>
  
  <p>But </p>
  
  <ul>
  <li>In situation 1 : "this.x" of function A isn't changed when assign "this.x = 2" in function B</li>
  </ul>
  
  <p>My code runs on Chrome v23</p>