Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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() { }


Actually that's not true at least in Firefox and probably chrome.

Take a look at 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)


It'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.


Not true as of 0.10.24, which is what I have installed.


JS 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.


Modern browsers does a very good job at figuring at a name for functions in stack traces, even when you'd expect them not to.


Maybe, 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

Is it really that much work to name your functions?


Awesome, I guess my info is out of date!



Kangax'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: