look at the following code:
function test(){
console.log(this === window);
show();
window.show();
function show(){
console.log(this === window, "fn");
}
}
function show(){
console.log(this === window, "local");
}
test();
:
true
true "fn"
true "local"
my understanding is:
1 who calls the function where this is located, this represents who
2 when a function and object is not called by an object, the default is window object
3 when using a variable or function, priority is given to variables and functions in the current scope
first question: do I understand correctly?
but (second question, divided into three small questions)
1 when show () is called in the test () function, is the window object called by default?
2 if the above is true, why is the result different from the explicit window call below?
3 do local variables and local functions belong to window objects?
Thank you all