jQuery anonymous function $(function(){ }

Original address for handling: https://zhidao.baidu.com/question/473318430.html

$(function(){ } is actually an anonymous function. This is the syntax of JQuery, and $ represents a JQuery object, which can be used in several ways. For example, passing selector strings, page objects, etc., if you pass the function body directly, it means This function is executed when the page is loaded.

 

This is actually an anonymous function "$(function(){ }", which defines an anonymous function. When the parameter is arg and the function is called, parentheses and actual parameters are written after the function. Due to the priority of the operator, The function itself also needs to use parentheses, that is: "$(function(){ }" This is equivalent to defining an anonymous function with parameter arg, and calling this anonymous function with param as a parameter and "$(function(){ } ” is the same, the reason why only $ is used in the formal parameters is to avoid conflicts with other libraries.

(funtion(){})(); executes the function immediately; it is equivalent to declaring a function first, and calling it directly after declaring it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324985646&siteId=291194637