0

Now I have some code:

window.testFun = {
   say() {
      console.log(this);
   }
};

window.testFun.say();     //  print say

window.console.log(this); // why not console but window?

I am sorry that my English is not very good, but I am actively learning English now, and I hope to be able to actively discuss the code with everyone

1 Answers1

1

The value of this is defined by the function this is used inside.

You are using it in the global scope. You are just passing it to log. It isn't a keyword inside the log function itself (which is built into the browser and you aren't looking at the source code for it).

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205