I use the Revealing Module Pattern quite a bit. I found an implementation written by Burk Holland and in the comments of Burk’s post Steve Howell and Elijah Manor provided additional implementations. Although, Burk’s example came close to what I was looking for in simplicity and cleanliness, I felt that there could be some improvements:
- It defined the module in the global namespace. I always create my modules in a namespace I define for the my project to further protect against naming collisions.
- I didn’t like how the module ended with the definition of a variable to contain the public functions.
I put forward the following:
I create an object as the last expression in the function that will be returned. This skips the creation of the temporary variable that is never referenced.