javascript, detecting line number of the calling function

Started by
5 comments, last by Mayple 12 years, 10 months ago
I have a debug print function like so :

function debugPrint(msg){
//...
}


I would like to add automatic line number detection, that is whoever calls the debugPrint function, that line number will also be displayed. Anyone know anyway of doing this without, actually doing something like, debugPrint("...", new Error().lineNumber)

I want to avoid having to pass the line number to the debugPrint.

any advice?
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
Advertisement
Have you searched Google?

Have you searched Google?


Actually it's not so straight forward a problem, as the way you would have done it was deprecated a few years ago ( Function.caller.lineNumber ) or something similar to that. These days there is no straight forward answer.
I guess I didn't search well enuf. Back to the google machine.
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
Looks like I'm a bad googler today, any help?
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
Check out Googling Java Line Numbers

(I dont use java)

Check out Googling Java Line Numbers

(I dont use java)


Thats a link to Java, which is a bit different than javascript.

You want something more like this:

http://www.webmonkey.com/2010/02/javascript_debugging_for_beginners/ *for line debugging stepping*
http://www.webreference.com/programming/javascript/rg31/ for understanding the errors

and probably going to be your best friend if your working with javascript: http://getfirebug.com/

Mayple
I usually just give my 2 cents, but since most of the people I meet are stubborn I give a 1$ so my advice isn't lost via exchange rate.

This topic is closed to new replies.

Advertisement