This module begins by talking about spaghetti code and naming conflicts that arise from spaghetti code.
Then Dan introduces closures and how they provide encapsulation. He gives a simple easy to understand date.milliseconds example.
Also covered is different ways to define variables
The module pattern “modularizes” your code, removes variables and functions from the global scope, and hides private members.
Dan explains that there are some disadvantages: potentially high memory usage (duplicated objects), difficulty in extending it, and greater difficulty with debugging.
Dan uses the same calculator example for the demo, so that you can compare the prototype and module patterns in a like for like way.
Revealing Module pattern
Dan says that the main difference between the module pattern and the revealing module pattern is the way to expose public members is a little bit “cleaner”. Dan prefers this pattern. It has the same disadvantages that the module pattern has.
Again, the demo creates a calculator, but Dan also shows an example of using this pattern when creating a population chart using the HTML5 Canvas object.
Revealing Prototype pattern
The revealing prototype is a combination of the revealing module pattern and the prototype pattern, providing the benefits of both.
Dan shows a couple of different techniques, and likes using the prototype call method
Experienced amateurs – 1.5x
Pros – 1.8-2.0x