如何在 Jquery 闭包中调试代码?
我试图通过利用既定的设计模式、避免污染全局命名空间等来成为一名更好的 javascript 开发人员。虽然我需要一些时间来适应不同的编码风格,但有很多好的资源。
我真正落后的地方是我的开发实践。我习惯于能够打开 Firebug / IE 或 Chrome 控制台并调用逐行测试和方法调用。对于所有设计模式来说,这似乎都不可能(我想是故意的)。
严肃的 JS 开发人员如何调试闭包等中的代码?
即:
$(function() {
...
[declare lots of vars, functions, page load actions, etc.]
...
}
我真的必须在各处插入调试/中断语句吗?然后确保它们在部署之前被包裹/清理干净?
I'm trying to become a better javascript developer by making use of established design patterns, avoiding polluting the global namespace, etc. While it's taking me some time to get used to the different style of coding, there are lots of good resources.
Where I'm really lagging is in my development practices. I'm used to being able to open Firebug / IE or Chrome console and invoking line by line tests and method calls. This doesn't seem possible with all design patterns (intentionally, I suppose).
How do serious JS developers debug code within closures, etc?
ie:
$(function() {
...
[declare lots of vars, functions, page load actions, etc.]
...
}
Do I really have to insert debug/break statements all over the place and then make sure they get wrapped/cleaned up before deployment?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看结果是什么
现在你可以调用类似
closure.bar()
的东西......只要你返回一个允许你访问闭包函数和你可以测试的变量的对象, 。有时我会在不关闭的情况下编写初始代码
并使其全部正常工作...然后将其包装在命名空间中,这样我就不必担心它...但是这是另一种方法
它实际上取决于您的代码风格和开发方式
经常测试早测试
祝你好运
now you can call something like
closure.bar()
... and see what the result isso long as you return an object that allows you to access the closure functions and vars you can test away...
sometimes I will write my inital code without closure
and make it all work... then wrap it in a namespace so I dont have to worry about it... but that is another approach
it really depends on your code style and how you develop
test early test often
best of luck