The journey begins
Refactor your code, force yourself to test through objects (because they have properties and methods that you can unit test) and break up your code in modules.
The following 3 resources were very helpful trying to answer this question:
A very simple module for addition and subtraction
This code basically creates an outer self executing anonymous function that returns an object literal which is assigned to the variable simpleCalc. There are 4 methods publicly available (add, sub, set and get) but there is no way to change the value of the privateCounter directly or to call the privateShowCounter function directly. Due to the public set and get functions though, it is possible to either change the value of the privateCounter or to retrieve its value for further processing.
So, what comes next?
This very simple module will do for today. In the meantime, I’ll be studying other design patterns, include jQuery events in modules and start unit testing. These topics are for a follow-up post!