javascript - Alternative syntax for self-invoking function? -
this question has answer here:
while writing javascript course coworkers, accidently discovered alternative syntax self-invoking function. know it, there specifics ? wasn't able find documentation it.
code : classic syntax
(function(){ console.log("i'm self-invoked!"); })();
alternate syntax
(function(){ console.log("me too!"); }());
thanks hints !
the 2 identical in meaning.
in both, (
@ start symbols start of expression. indicates start of a function expression intend invoke. invoke it. difference subtle , should not matter @ all, let's explore it:
(function(){ console.log("i'm self-invoked!"); })();
here, (
tell compiler it's start of expression, compiler evaluates expression (a function expression in case) , invokes (outside expression).
(function(){ console.log("me too!"); }());
here - invokation pattern ( ()
) part of expression.
Comments
Post a Comment