Basic Javascript knowledge in Jquery source code (1)
Jquery Source Code involves a lot of native js knowledge and concepts. This article is a summary of my work in learning the two. If you have any mistakes, please let us know. You can check the source code and find that the overall structure is as follows: (function (window, undefined) {// code}) (window); to understand this writing method, there are two methods to define functions in js: 1. function declaration function functionName () {// code} 2. function expression var functionName = function () {// code} the function defined in this way is also called an anonymous function (without a function name). It can be considered to assign a function expression to a variable. Call the function after the function is defined: functionName (); here we can compare the source code to find that functionName is replaced by its corresponding value (expression), namely: (function () {}) (); // if no parentheses are added, the Code indicates that an anonymous function is defined and executed immediately. Let's look at another example to help us understand that when passing parameters to a function, var num = 1; functionName (num); functionName (1); parameters can be passed to variables or directly to values (expressions ), similarly, the function name can be replaced with its corresponding value (function expression ).