Whew it’s been a while since I last posted here! I have moved to from London to Malaysia in that time :)
//START TOUCH EVENT HANDLERS and
//END TOUCH EVENT HANDLERS.
Later on I discovered JSLint which saved me from a large number of “stupid” bugs, although I was still manually copying and pasting my code into the online linter :-O
I am using my own custom build system, with my code separated into files that deal with a certain piece of functionality which are then concatenated together, checked for errors and minified with one command line.
I based my system on this system (which can be found in the jQuery GitHub repository) which works as follows:
BASE_FILESand then wrapper with an intro and outro script in
make lintwhich will check the built file against JSLint and output any errors to the console
make minwhich minifies the code using uglify.js
As I am building a number of different Ad products, which often share similar functionality, I have my own build scripts which work in a similar way but with the ability to build different combinations of files.
Firstly, I use the product name as the target (e.g.
make product.js) with rules in my makefile for the specific set of files required to build that product. This allows me to share files between the products easily, which used to involve copy and pasting blocks of code!
Also, instead of using JSLint I prefer to use JSHint as I find it’s rules more suited to my coding style. I pull in the JSHint repository as a submodule so that I can update it easily and track the version I am using.
Finally, I use the Google Closure Compiler instead of uglify.js (or various other alternatives). I like this as it really compresses my code a lot (Advanced mode, with the code written to work with this) and it provides additional checks to my code such as type checking (via JSDOC comments) and missing property checks. I use the downloadable JAR file to run this locally, although it does take a few seconds to run on larger code bases, I feel it is worth it.
My scripts also will push versioned builds to the live servers, to ease that step too.
Although it takes a little while to setup these automated scripts, it really is worth it in the long run. As so many bugs can be picked up immediately (without opening a browser or test suite), and changes can easily be made to a shared file and then all products using that can be rebuilt and receive the upgrades in a much shorter time period.
I would advise anyone to automate as much of their manual process as possible, as it will make your life easier.