Development Blog

Naming Anonymous JavaScript Functions

Tired of ?() or anonymous in your call stack in Firebug. Me too! Fortunately Salman Mirghasemi has a solution: a new algorithm for Naming Anonymous JavaScript Functions detailed in a paper by Salman, John J. Barton (that’s me), and Prof. Claude Petitpierre submitted to Splash/Wavefront 2011.

A few key points from the paper:

  • Among the 90,000 functions in 10 libraries surveyed, less than 7% were named.
  • The name-guessing schemes in Firebug and Web Inspector guess right …sometimes 😉
  • Anonymous functions are used in lots of complex ways!
  • The Static Function Object Consumption algorithm names 99% of the the functions.
  • The new algorithm generalizes the approach used by existing tools.

The paper shows examples from many popular libraries like jQuery, dojo, ExtJS, and so on.

The algorithm only requires a parser, so its easily implemented in JavaScript engines. Since Firebug does not have a JavaScript parser, we have to start by borrowing one.


For comments and suggestions, please post to the Firebug newsgroup.

Comments are closed.