4 ms·
You can just parse (new Error).stack: var __LINE__ = (new Error).stack.split("\n")[1].match(/:([0-9]+):/)[1];
by niggler 14y ago
You can just parse (new Error).stack:
var __LINE__ = (new Error).stack.split("\n")[1].match(/:([0-9]+):/)[1];
- cristiantincu 14y ago`(new Error()).stack` is non-standard. But that’s a nice hack, nevertheless.
- niggler 14y agoThe underlying construct (console.log processing "%c" and styles) is nonstandard to begin with.
- cristiantincu 14y agoYes. It will not break, though. Unless you’re running it on an old IE that doesn’t host the `window.console` object.
- tracker1 14y agoI do something similar for logging my node apps... in .Net I use reflection for essentially the same.