thisThe keyword is a very important grammatical point. It is no exaggeration to say that, without understanding its meaning, most development tasks cannot be completed.
First, this always return an object, simply, to return the object where the property or method "current" is located.
Here are two examples to make people more intuitive:
var person = { name: ' Zhang San ', describe:function () { return ' name: ' + this.name; }}; Person.describe ()//"Name: Zhang San"
function f () { return " name: " + this .name;} var A = {name: " Zhang San " , describe:f}; var B = " John Doe " , describe:f}; A.describe () // "name: Zhang San" B.describe () // "Name: John Doe"
Looking at these two examples, here's a summary:
Global environment, constructors, methods of objects, these three situations this point is not the same, so be aware of the use.
The last hint, do not use multi-layer this in the function
The meaning and explanation of JS this