31 May '13, 1pm

Module Pattern in JavaScript and CoffeeScript

May 31, 2013 brittballard javascript coffeescript Module Pattern in JavaScript and CoffeeScript One of the shortcomings of JavaScript objects is the lack of support for private members. The ability to create private members makes external APIs more meaningful and helps keep code more manageable and DRY. The Module Pattern , pioneered by Douglas Crockford while building the YUI library, is a mechanism that allows for creating public and private members in JavaScript. This post looks at the pattern in both JavaScript and CoffeScript. The object literal The foundational element of the Module Pattern is the object literal , which provides the ability to create instances of objects without instantiating them. One of the big wins provided by object literals is the ability to add namespaces to your JavaScript code. When you declare a variable outside of an object literal or funct...

Full article: http://robots.thoughtbot.com/post/51801869159/module-patt...

Tweets