In Javascript, what is the motivation or advantage of using var foo = function foo(i) { ... }? -
I see that
in response to < P> Whatever it is doing
var foo = function foo (param) {...}
In that special case, why do this Are just using
function foo (param) {...}
?
Soon, if you take the following code, then the first example is foo
Creates a function called, the second example creates an anonymous function and specifies it in the bar
variable. In addition to style, the basic difference is that before the definition, code can be said in the code (because it is the name of the function); Otherwise, before getting the bar
assignment, there is an undefined variable, so can not be used before.
var foo_result = foo (123); // ok function fu (param) {/ * ... *} var bar_result = bar (123); // error: there is no undefined function var bar = function (param) {/ * ... *} var bar_result = bar (123); // ok
I would recommend you to read Pekka's suggestion.
Comments
Post a Comment