Skip to content

Instantly share code, notes, and snippets.

@anio
Created January 25, 2015 12:40
Show Gist options
  • Save anio/047049e5d73aafaa8dd2 to your computer and use it in GitHub Desktop.
Save anio/047049e5d73aafaa8dd2 to your computer and use it in GitHub Desktop.
__line : Return Line Number
Object.defineProperty(global, '__stack', {
get: function(){
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;
return stack;
}
});
Object.defineProperty(global, '__line', {
get: function(){
return __stack[1].getLineNumber();
}
});
// usage: console.log(__line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment