Home > front end >  Several problems about function immediately
Several problems about function immediately

Time:10-06



Function immediately
1, the way a

(function () {//open IIFE
//inside IIFE
} ());//close IIFE
2, the way 2
(function () {//open IIFE
//inside IIFE
}) ();//close IIFE

Questions as follows:

1, 1 ( the function () {} () ) in the function () {} after plus one () how to understand

In the way of 2, 2 a () (), how to understand

3, why
The function () {//open IIFE
//inside IIFE
} ();//close IIFE

This form can be not?

4, function must be executed immediately, this expression is what meaning, don't understand, a confused ah,

CodePudding user response:

Question 1
The equivalent of
A=function () {};//a is the method object or function pointer
(a);//brackets is a method call
If the method has a parameter
A=function (STR) {};
A (" test ");//, it is not only the bracket and with parameter

Question 2
Parentheses role with problem 1

Question3:
Effect is equivalent to question 2, the method of problem just 2 objects with parentheses, according to the priority, the brackets are all influence the results

Question 4
The function (STR) {}; Just method definition, so is not the expression, but the method invocation is expression, so be function (STR) {} (); In front of the function (STR) {} represents the object (or a function pointer), the brackets behind the said method calls,
  • Related