What is this in 1.javascript?
This refers to the principal that the current behavior is executing, or the principal that the current method executes
Context: The environment in which the current behavior or method is executed
Instance:
XX go to Beijing Hotel to eat; the context is "Beijing hotel", this is XX
2. So how can you tell who the This keyword is in the body of a function when it executes? There are several main rules:
1) The This keyword in a function body and where the function is defined, where execution is not related;
2) When judging the execution of a method, who is the executing body of the function? The main thing to see is that there is no point (.) in front of the method, and if the function is executed, the function is preceded by a bit (.), and the point (.) is preceded by WHO, when the function is executed, who is the This keyword in the function body;
And look at the code:
When the function executes, there is no point in front of the case:
function fn () { Console.log (this= 'Windwo ";
FN ();
When the function is executed in a xx.fn manner:
person = { name:' Alice ',}function fn () { Console.log (this . name);}
= Fn;person.fn ();
3) The This keyword in the function body is always the Window object (and where the self-executing function executes without any relationship), since execution of the function is performed;
4) An event that is bound to an element, when the event is triggered, is bound to an event handler on the element being executed, and the This keyword of the function points to the element of the binding event;
The This keyword in JavaScript is detailed