This is not a function.
(function() { ... })()
automatically evaluates anonymous function. And the result of the assessment, apparently, does not return the functional object in this case :-)
Consider:
f = (function() { return "not a function :(" })() alert(f())
and
f = (function() { return function () { return "Yay!" } })() alert(f())
Happy coding :)
Here is a function that will "execute something once" and then "return something to execute later." (See "You can either [assign] a function or call it, you cannot execute both ..." from Slaks answer.) However, I would not do it like that.
Init = (function () { function Init () { alert("whee!") } Init() return Init })() Init()
Here is another solution (much shorter / cleaner) from CD Sanchez (see comment) that uses the fact that assignment is evaluated by the assigned value:
var Init; (Init = function Init () { alert ("wee"); })()
user166390 May 22 '11 at 21:33 2011-05-22 21:33
source share