0

this.x = 9;
var module = {
  x: 81,
  getX: function() { return this.x; }
};

module.getX(); // 81

var getX = module.getX;
console.log(getX())  // 9

In the first situation i understand that x = 81, because it point to the outer scope where x = 81, but
why getX at the end is 9?

Asking
  • 1,167
  • 4
  • 15
  • 2
    You are implicitly calling `window.getX()`, which scopes `this` to `window` inside the return of `module.getX`. So you get `window.x` which has been assigned the value `9`. – Mr. Polywhirl Feb 09 '21 at 20:21

0 Answers0