When I try to debug the javascript code which has a lot of closures I use to put a breakpoints.
Then I go to see the stack but most of the times I just see a call stack full of anonymous functions which is a nightmare for me.
What is the best way to debug closure in javascript?
You can add a name to the callback function. That way the function name will be shown during debugging.
As an example in jQuery
$('div').each( function divLoop() {
..
});
In OOP Javascript, it's common to call the function as the name of the method
MyClass.prototype.methodName = function methodName() { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With