I saw the second usage environment when the master introduced this. The original text is here:
http://www.ruanyifeng.com/blo...
The object o here should be this? If so why is this least congruent?
function test(){
console.log(this.x);
}
var o = {};
o.x = 1;
o.m = test;
console.log(o.m());
console.log(o===this);
The output is:
1
false
This===window in global view
When console.log() is executed in the global environment, this of course points to the window;
this points to the current execution environment of the function
o.m() implicitly binds this to the o object
In the global scope, this points to the global object
Remember, there is another calling method func.call(context, x, m). The above two methods are just syntax sugar. You can use "conversion code" method such as:
is equivalent to
Logically speaking, the printed this should be undefined
But there is a rule in the browser:
If the context you pass is null or undefined, then the window object is the default context (the default context in strict mode is undefined)
So the this above should correspond to window.