Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can just parse (new Error).stack:

    var __LINE__ = (new Error).stack.split("\n")[1].match(/:([0-9]+):/)[1];


I do something similar for logging my node apps... in .Net I use reflection for essentially the same.


`(new Error()).stack` is non-standard. But that’s a nice hack, nevertheless.


The underlying construct (console.log processing "%c" and styles) is nonstandard to begin with.


Yes. It will not break, though.

Unless you’re running it on an old IE that doesn’t host the `window.console` object.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: