javascript - Immediate function invocation syntax -
there jslint option, 1 of parts in fact, "[requires] parens around immediate invocations," meaning construction
(function () { // ... })();
would instead need written as
(function () { // ... }());
my question -- can explain why sec form might considered better? more resilient? less error-prone? advantage have on first form?
since asking question, have come understand importance of having clear visual distinction between function values , values of functions. consider case result of immediate invocation right-hand side of assignment expression:
var somevar = (function () { // ... }());
though outermost parentheses syntactically unnecessary, opening parenthesis gives up-front indication value beingness assigned not function rather result of function beingness invoked.
this similar crockford's advice regarding capitalization of constructor functions -- meant serve visual cue looking @ source code.
from douglass crockford's style convention guide: (search "invoked immediately")
when function invoked immediately, entire invocation look should wrapped in parens clear value beingness produced result of function , not function itself.
so, basically, feels makes more clear distinction between function values, , values of functions. so, it's stylistic matter, not substantive difference in code itself.
updated reference, old ppt no longer exists
javascript syntax jslint iife
No comments:
Post a Comment