开发者

Difference between 'var foo = function ...' and 'function foo() ...' [duplicate]

This question already has answers here: Closed 12 years ago.

Possi开发者_如何学Cble Duplicates:

“Usual” functions vs function variables in JavaScript

What do you call this JavaScript syntax, so I can research it?

Is there a fundamental difference between

function foo()
{
    things();
}

and

var foo = function()
{
    things();
}

Or is function ... just syntactical sugar?

Thanks in advance.


They are different (but produce similar results). Basically, the first is an actual named function. The second is a regular variable declaration with an anonymous function attached to it. There are some subtle differences...they are summed up nicely here:

JavaScript Function Declaration Ambiguity (Be sure to read the comments too...more good info there)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜