This article mainly introduces how to analyze the apply and call methods of JavaScript Functions from JQuery source code. This article explores the apply and call methods again by combining JQuery source code and js advanced programming, for more information, see $. when the each method is very, suddenly think of $. each ($ ('P'), function (index, entity) {}); where did the index and entity come from, and they are dispensable, in addition, such a high level tells us the subscript and instance of the current traversal. So let's take a look at the jQuery source code, which is written in this way:
During debugging, the Code marked with red is used, and then the callback. call function is used. So I looked at js advanced programming, which has a deep explanation.
First, a function is a pointer to a Function object, and a function name is a pointer to a Function. In the function body, there will be a scope, that is, the this keyword.
This keyword indicates the function running scope. For example:
The Code is as follows: