Sign in to follow this  
Concentrate

javascript, detecting line number of the calling function

Recommended Posts

Concentrate    181
I have a debug print function like so :
[code]
function debugPrint(msg){
//...
}
[/code]

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, [i] debugPrint("...", new Error().lineNumber) [/i]

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

any advice?

Share this post


Link to post
Share on other sites
Serapth    6671
[quote name='rip-off' timestamp='1307477703' post='4820668']
Have you searched Google?
[/quote]

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.

Share this post


Link to post
Share on other sites
yewbie    677
Check out [url="http://stackoverflow.com/questions/115008/how-can-we-print-line-numbers-to-the-log-in-java"]Googling Java Line Numbers[/url]

(I dont use java)

Share this post


Link to post
Share on other sites
Mayple    187
[quote name='yewbie' timestamp='1307556712' post='4821008']
Check out [url="http://stackoverflow.com/questions/115008/how-can-we-print-line-numbers-to-the-log-in-java"]Googling Java Line Numbers[/url]

(I dont use java)
[/quote]

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

You want something more like this:

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

and probably going to be your best friend if your working with javascript: [url="http://getfirebug.com/"]http://getfirebug.com/[/url]

Mayple

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this