How do you stay on top of a complex JavaScript project?

a 夏天 提交于 2019-12-04 04:12:07

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.

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.

I worked in a Web2.0 with many javaScript and etc.. I`ll give some tips that helped me:

Try aptana, help with code complete,validations, etc. (have ext-je,Jquery plugins)

Try JSLint, helps me allot to solve problems specially when dealing with Internet Explorer.

Try YSlow to see your site grades.

Try WATIR, tool that you could create many test cases like: clicking anywhere wait some text appear some where, write some string to some field, generate logs.

Remember to put Id`s in everywhere that you could.

Define a code conventions could help. (link1 - link2)

[Updating] I was looking in my bookmark and found a very great video about: Maintainable JavaScript take a look.

Hope these simple tips could help!

Cheers!

You might want to invesigate introducing actual unit tests into your code. There are a variety of javacscript unit test platforms available, such as fireunit. If your already have FireBug installed this is a pretty short jump to the happy comfort zone!

Give it a shot, even small amounts of unit test coverage will help ease your mind!

Any time a program starts to slip away from you you need to stop and take a close look at how to break it into pieces. Think about breaking the js into separate files so you don't have to keep the whole thing in your head at once. Anything you can treat as "done" can be made into an interface where you don't care about the guts of it anymore.

It's all about hiding the mess. Whether it's OO or procedural. Many people have the same problem with PHP and C as you are having with JavaScript, so you can search for "PHP spaghetti" and get some good tips.

Use a good JavaScript debugger like Firebug and the debugger statement to add breakpoints to your JavaScript. Just be careful to remove them after you're done.

You might want to think about using GWT.

  • Superior support.
  • Classes
  • Ability to refactoring.
  • No name space conventions - use packages.

For a more comprehensive list of "reasons" read those given by the GWT team.

If it's getting too complex you are doing too much so keep it simple (ie: break it into manageable and reusable chunks so instead of having one Titanic you have many compact lifeboats). This might be the best non-technical advice anyone can give you--and it's valid.

One thing that helped me get a handle on a complex JavaScript code base that I inherited was the AOP package in dojo.. Using it, you can get a nicely formatted execution path of your code (kind of like Firebug's profile but in a list in the order the methods were invoked).

I don't know if jQuery has something similar but it might be worth looking into because it beats the snot out of littering your code base with log statements that you may (or may not depending) have to remove.

Once you know how things are working, you can go about re-organizing it using some of the excellent tips here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!