- Modularise JS code (JAWR helps)
- Unit test it. (we use Jasmine and JSTestDriver)
- Static analysis, “checkstyle for JS”. (we use JSHint)
- JS Dependency Injection to facilitate testing
Here are the slides with more info and some code samples.