本文介绍了您如何保持复杂的JavaScript项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebug来帮助弄清楚我的JavaScript(+ JQuery)代码中发生了什么。我主要使用它打印出大量的 console.log 语句。这可能不是保持项目最佳的最有效方式。由于它已经从几个功能发展到超过一百个,我开始对一切如何融合起来感到困惑。我的意思是,它以某种方式工作,但是当我看到代码时,我几乎觉得别人写了它,因为它太混乱了。

I'm using Firebug to help figure out what's going on in my JavaScript (+JQuery) code. I'm mainly using it to print out tons of console.log statements. This is probably not the most efficient way to stay on top of the project. As it has grown from just a few functions to over a hundred I am starting to get confused about how everything fits together. I mean, it works somehow but when I look at the code now I almost feel like someone else wrote it because it's so confusing.

现在我有一个疯狂的数量 console.log 语句出现在控制台中,我一直把它留在那里,因为当我拿出一些时,我总是会重新创建它。我认为,这使得事情变得更加令人困惑,而不是我根本没有记录。我从未真正探索过真正的调试 - 断点,监视变量等 - 这是重新获得对该项目的控制权的好方法,还是有其他可能有用的工具?

Now I have a crazy amount of console.log statements appearing in the console whenever I run my app in Firebug and I've been leaving it there because I always end up recreating it whenver I take some of it out. This is making things even more confusing, I think, than if I had no logging at all. I never really explored real debugging - breakpoints, watch variables, etc - would that be a good way to regain control of this project or are there any other tools that might help?

我已经考虑过尝试绘制所有CSS的图表,并尝试将类和ID映射到我的JavaScript中的相应函数。该项目基于一组复杂的应用程序状态组合使用了大量丰富的交互和显示/隐藏功能,可能更接近您在Flash / Flex应用程序中找到的内容。

I've thought about trying to draw a diagram of all of my CSS and try to map out the classes and IDs to the corresponding functions in my JavaScript. This project uses a lot of rich interaction and show/hide functionality based on a complex set of combinations of application states, closer to what you would find in a Flash/Flex application perhaps.

对于可能有助于重新获得对该项目的控制的工具或方法的任何建议将不胜感激。当我开始这个项目时,我感觉非常好,因为它看起来很好,人们会赞美它有多酷,但现在感觉就像失败一样,因为我认为我甚至无法解释它是如何工作的如果我不得不接受面试。

Any suggestions for tools or approaches that might help to regain control of this project would be appreciated. When I started this project I felt really good about it because it looked so good and people would give me compliments on how cool it was but now it just feels like a failure because I don't think I could even explain how it works in a job interview if I had to.

推荐答案

保持你的代码有条理。使用命名空间将其分解为逻辑模块。寻找常见的交互模式并开发通用的可重用代码也是明智的。

Keep your code organized. Use namespaces to break it down into logical modules. It might also be wise to look for common interaction patterns and develop generic reusable code.

我尝试将每个新功能都编写为jQuery插件。这迫使我编写一个与样式和标记不相关的可重用代码。

I try to write every new feature as a jQuery plugin. That forces me to write reusable code that is not so coupled with the style and markup.

这篇关于您如何保持复杂的JavaScript项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 03:36