JS in the method when the parenthesis when the parentheses, we sometimes do not know, remember that the following points are good to understand.
1. Do not add parentheses to the function when making arguments.
function Fun (a) { alert (a);} function Gete (fun,e) {fun (e);} Gete (fun,3); // Popup 3, here the function fun as an argument passed in, so there is no parentheses.
2. When the function call is to be bracketed, the above example gete this function call, regardless of whether there are parameters, are parentheses.
3. When the function is to the right of the assignment symbol, the parentheses represent the object of the transfer function, which indicates that the return value of the function is passed. The same is true when a statement is returned as a retrun.
function Fun () { console.log ("666");} // var getfun = fun (); so you hit 666 straight. var getfun = fun;getfun (); // This is a reference to the function, which is to be executed with parentheses to invoke.
The above example is quite simple, let's look at this slightly more complex.
function F1 () { var n = 999; function F2 () { alert (n); } return F2;} var result = F1 (); // here is the function to execute F2, so F1 parentheses, passing his return value, here is F2. result (); // then the parentheses are removed with F2, so the result pops up 999.
What if we remove the brackets from the F1 and still have to eject n? We can do this:
functionF1 () {varn = 999; functionF2 () {alert (n); }returnF2 ();//so I'm going to put a parenthesis in here so that we can return to F2 and then call and Pop N. }varresult = F1;//Here we take the parentheses out of the F1, and that's the reference to the function.Result ();//and then it just executes the F1 function. The result is a return to F2, which will not eject N
The final conclusion: we just need to remember the last point, we can: no parenthesis means the transfer function of the object, when the parentheses indicate that the return value of the function is passed.
Question about whether the method in JS is bracketed