javascript - Why is the parenthesis missing in this anonymous function call? -
this question has answer here:
i reading book , has code example
function getfunction() { var result = []; (var = 0; < 10; i++) { result[i] = function(num) { return function() { console.log("this " + num); } }(i); }; return result; } it working ok why anonymous function here not wrapped in parenthesis (function(...))(i); ? , in cases can parenthesis omitted in anonymous function?
since syntax function declarations , function expressions identical, js tells 1 using code around function.
to stop being function declaration need use in expression. wrapping in parenthesis will preceding = (as host of other operators). since there = here, parenthesis unnecessary.
Comments
Post a Comment