Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 9, 2012 23:27
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save isaacs/1784220 to your computer and use it in GitHub Desktop.
function getLine () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
var s = stack[0];
var l = s.getLineNumber();
return s.fun.toString().split(/\r?\n/)[ l - 1 ];
};
// outputs 'console.error(getLine());'
console.error(getLine());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment