javascript - How to understand this js code?
PHP中文网
PHP中文网 2017-06-26 10:57:20
0
3
725

My doubt is what do the parentheses surrounding this function mean, closure?
Then (1) at the end of the method is to bring parameter 1 into this anonymous method?
Does the lexicon of these parentheses mean execution or isolation method?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
typecho

It means to execute immediately, pass in parameter 1

(function(x){

})(1)
巴扎黑

This is an immediate execution function. The immediate execution function constructs a function scope, which can play a role in isolation and avoid polluting the global scope. Passing in 1 is the incoming parameter. The immediate execution function can be used to solve closure problems. . But it is not directly related to closure.

给我你的怀抱

Anonymous functions do not have a function name and cannot be called. When the function declaration is enclosed in parentheses, it is no longer a function declaration, but a function expression. Adding () after it means executing the function immediately. 1 is the parameter, which is received by x inside.
You can understand it as

var foo = function(x){
    delete x;
    return x;
};
foo(1);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template