Skip to content

Instantly share code, notes, and snippets.

@bajtos
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bajtos/8868797 to your computer and use it in GitHub Desktop.
Save bajtos/8868797 to your computer and use it in GitHub Desktop.
JavaScript function displayName
var f = function() {
throw new Error('oops');
};
f.displayName = 'myfunc';
f();
$ node -v
v0.10.24
$ node test.js
test.js:2
throw new Error('oops');
^
Error: oops
at f (test.js:2:9)
at Object.<anonymous> (test.js:7:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
@ritch
Copy link

ritch commented Feb 7, 2014

try {
  var f = function() {
    throw new Error('oops');
  };

  f.displayName = 'myfunc';

  f();
} catch(e) {
  console.log(e.stack);
}

output:

Error: oops
    at f (<anonymous>:4:11)
    at <anonymous>:9:3
    at Object.InjectedScript._evaluateOn (<anonymous>:603:39)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:562:52)
    at Object.InjectedScript.evaluate (<anonymous>:481:21) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment