Created
January 29, 2016 04:26
-
-
Save mattness/adc451d095349c1d5468 to your computer and use it in GitHub Desktop.
Anonymous vs Named functions in backtraces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var EventEmitter = require('events').EventEmitter; | |
| var e = new EventEmitter(); | |
| e.on('something', function() { | |
| throw new Error('anonymous function crash'); | |
| }); | |
| e.on('something_else', function foo() { | |
| throw new Error('named function crash'); | |
| }); | |
| e.emit(process.argv[2]); |
Author
This is a good practice to follow. Thank you ^ ^
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a simplistic example, but notice that the backtrace for the
somethingcrash just says<anonymous>for the function name, and the backtrace for thesomething_elsecrash hasfoofor the function name.Not much more valuable in such simple code, but imagine a more complex script, with lots of anonymous functions in the stack. It gets a lot easier to understand at a glance when all those anonymous functions have names instead.