3 ms·
> Generally it's considered idiomatic to just avoid named functions altogether. This is not idiomatic. Many developers only use named functions. The obvious r
by secoif 13y ago
> Generally it's considered idiomatic to just avoid named functions altogether.
This is not idiomatic. Many developers only use named functions.
The obvious reason is they make stack traces far more readable, though you can get around this by naming functions anyway:
var myFunction = function myFunction() {}
The hoisting 'nuances' you decry are a boon. Hoisting means you never have to worry about the order functions are declared – especially useful in cases where your functions call each other. You also get another avenue to declutter your code by pushing any crufty utility functions to the bottom of the page.
- lowboy 13y agoNamed function expressions will cause memory leaks in IE < 9. Shouldn't be a problem forever, but some devs now might be impacted. Pushing utility functions to the bottom of the current file is another reason to use a modular js architecture.