0

When executing this code below, results are false, why? What is "this" bound to? I was expecting the results to be true in both alert statements

(function(win){

     alert("this == win: "+ this == win);         // false
     alert("this == window: "+ this == window);   // false

})(window);
Nora
  • 65
  • 4

1 Answers1

7

It is nothing to do with this not equal window, it is an order of operation issue....

what the parser sees is this:

("this == win: "+ this) == win

Add in the correct parenthesis

(function(win){

     console.log("this == win: "+ (this == win));        
     console.log("this == window: "+ (this == window));   

})(window);
epascarello
  • 204,599
  • 20
  • 195
  • 236