3 ms·
One big difference is that: function functionName() will show up in a stack trace with a name, whereas the other won't. You can also do this: var f
by schrodinger 13y ago
One big difference is that:
function functionName()
will show up in a stack trace with a name, whereas the other won't.
You can also do this:
var f = function functionName() { }
- ahoge 13y agohttp://kangax.github.io/nfe/ http://kangax.github.io/nfe/
- jakub_g 13y agoKangax's article is the best and most detailed piece of writing ever on NFEs, including crazy implementation bugs in IE and other old versions of the browsers.
- evilpie 13y agoActually that's not true at least in Firefox and probably chrome. Take a look at http://jsfiddle.net/2LsSg/ http://jsfiddle.net/2LsSg/. window.onload/g@http://fiddle.jshell.net/2LsSg/show/:23:5 window.onload/f@http://fiddle.jshell.net/2LsSg/show/:26:5 @http://fiddle.jshell.net/2LsSg/show/ line 29 > eval:1:1 window.onload@http://fiddle.jshell.net/2LsSg/show/:29:1 (I guess jsfiddle wraps the JS code in a window.onload handler, which makes this a bit more ugly)
- randallsquared 13y agoIt's true in node.js, as of last year, which is where I use the style "var name = function name(){};", because debugging dozens of anonymous functions in node.js' callback playground will ruin your day.
- thedufer 13y agoNot true as of 0.10.24, which is what I have installed.
- badman_ting 13y agoJS engines are getting smarter about this, but you can't really rely on it. I suggest naming your functions if don't want them to be anonymous.
- nadaviv 13y agoModern browsers does a very good job at figuring at a name for functions in stack traces, even when you'd expect them not to.
- schrodinger 13y agoAwesome, I guess my info is out of date!
- protonfish 13y agoMaybe, but the profilers in Chrome and Firebug do a terrible job, not to mention tools like Visual Event http://www.sprymedia.co.uk/article/visual+event+2 http://www.sprymedia.co.uk/article/visual+event+2 Is it really that much work to name your functions?