Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the code line number where function is called

I searched a lot but could not get correct / updated answer (arguments.caller.callee does not exist it seems). I want to know the code line number where a particular function is called. I got this solution where function caller name can be retrieved .

But I am calling my function in JQuery UI droppable. For eg:

$("#id").droppable({

stop: function(e,u){

   main(); // I want this line number
}

});

Thats the reason I wanted to know the line number . Is there any way ?

like image 261
Amar Singh Avatar asked Apr 25 '26 14:04

Amar Singh


1 Answers

If you use console.error(), it will show the call stack and the line numbers (at least in Chrome, when you click the small black arrow):

function foo(){
    bar();
}

function bar(){
    console.error("hello");
}

foo();

Will show:

enter image description here

Check this fiddle (console.error doesn't work properly in the snippet): https://jsfiddle.net/fs1qqe77/

like image 82
Gerardo Furtado Avatar answered Apr 27 '26 05:04

Gerardo Furtado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!