标签云

微信群

扫码加入我们

WeChat QR Code

Possible Duplicate:JavaScript: var functionName = function() {} vs function functionName() {}In JavaScript, what's the purpose of defining a variable as a function? I've seen this convention before and don't fully understand it.For example, at some point in a script, a function is called like this:whatever();But where I would expect to see a function named whatever, like this:function whatever(){}Instead I'll see a variable called whatever that's defined as a function, like this:var whatever = function(){}What's the purpose of this? Why would you do this instead of just naming the function?


They're called anonymous functions: helephant.com/2008/08/23/javascript-anonymous-functions

2019年06月20日18分04秒

great and usefull, thanks : )

2019年06月19日18分04秒

DanielAndresAcevedo: Thanks. It was also slightly out of date, I've added a note at the end.

2019年06月19日18分04秒