admin管理员组文章数量:1394990
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?
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?
Share Improve this question edited Feb 21, 2012 at 15:07 c69 21.6k8 gold badges55 silver badges83 bronze badges asked Feb 21, 2012 at 14:51 antonjsantonjs 14.3k15 gold badges70 silver badges91 bronze badges 1- it depends pletely on what the problem is...can you be more specific? – hvgotcodes Commented Feb 21, 2012 at 14:54
3 Answers
Reset to default 5You 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 mon to call the function as the name of the method
MyClass.prototype.methodName = function methodName() { ... }
Well, in Google Chrome, you can see variables content throughout closures:
Local is the current execution context
Closure is its enclosing execution context
...
Up to the global execution context
Instead of providing anonymous functions as your callback, try declaring a function and use that instead.
http://jsfiddle/v9Fas/
This way you can debug inside of the callback function just like a normal function call.
本文标签: Debugging closures in javascriptStack Overflow
版权声明:本文标题:Debugging closures in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744110862a2591285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论