JavaScript anonymous functions

Reprinted from: https://www.cnblogs.com/ClareZjy/p/6365891.html
 
Zero: Introduction

The basic form of an anonymous function is (function(){...})();
The first parenthesis contains the function body, and the last parenthesis is to pass parameters to the anonymous function and execute it immediately.
The role of anonymous functions is to avoid the pollution of global variables and the conflict of function names
 
The role of parentheses
Parentheses can combine our expressions into blocks, and each block, that is, each pair of parentheses, has a return value. This return value is actually the return value of the expression in parentheses. Therefore, when we enclose an anonymous function with a pair of parentheses, in fact, the parentheses return the Function object of an anonymous function. Therefore, a pair of parentheses plus an anonymous function gets us its reference position just like a function with a name. So if you add a parameter list after this reference variable, you will achieve the normal function call form.
Simply put, the parentheses have a return value, that is, the return value of the function or expression in the parentheses, so the return value of the function in the parentheses is equal to the return value of the parentheses.
 
Example:
(function(){
    console.log('hello');
})();

 

One: The actual situation encountered


 

When learning RequireJS, I encountered the following way of writing

require.config({
    paths : {
        "jquery" : ["http://libs.baidu.com/jquery/2.0.3/jquery"]   
    }
})
require(["jquery","js/a"],function($){
    $(function(){
        alert("load finished");  
    })
})

The above function($).. how to understand this form?

Guess you like

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