2

I'm debugging some legacy javascript that has some freezes when executing. I've been at it for days and am making no progress. I need to be able to identify which functions are causing the freezes, and using the browser's debugging tools just isn't working.

Ideally, I'd like to be able to log the name of a function to the console when it's called, but I've got hundreds of functions, and don't want to manually add console.log statements to each one.

Is it possible to modify the function prototype or something so that it will log it's own name?

JEJoll
  • 547
  • 1
  • 6
  • 20
  • 4
    Did you look at the performance tab, you can see every function and the time it took to execute it there. – Sebastian Speitel Jan 17 '19 at 16:01
  • Took the words from my brain! Although, sometimes it's better off to just stick a `debugger;` in each function and just step through it so you can be sure. –  Jan 17 '19 at 16:02
  • Did you try [this](https://developers.google.com/web/tools/chrome-devtools/rendering-tools/) (note that timeline is called performance now) – HMR Jan 17 '19 at 16:17
  • What does 'freezes' mean? As in it crashes the browser tab? – Jared Smith Jan 17 '19 at 16:25

2 Answers2

0

This is what I use when I find myself in situations like yours, works every time.

function somename() {
  return somename.name;
}
somename();
squeekyDave
  • 918
  • 2
  • 16
  • 35
  • Note that this is not much less labor-intensive than adding logging statements to each function. – Jared Smith Jan 17 '19 at 16:25
  • @JaredSmith I agree, but OP wanted to know the name of the function when it's being called, this will give him the name of the function every time in the return statement, which of course can console.log. – squeekyDave Jan 17 '19 at 16:32
  • OP mentioned manually adding logging statements to every function and says that he/she doesn't want to do that. – Jared Smith Jan 17 '19 at 16:52
-1

Try making a function called log(function) that will log the function in the parameter and then execute the function in the parameter.