Skip to content

Instantly share code, notes, and snippets.

@ellm
Created January 25, 2016 19:31
Show Gist options
  • Save ellm/48ef5d594b87d3b318db to your computer and use it in GitHub Desktop.
Save ellm/48ef5d594b87d3b318db to your computer and use it in GitHub Desktop.
JavaScript - Module Pattern Example
function CoolModule() {
var something = "cool";
var another = [1, 2, 3];
function doSomething() {
console.log( something );
}
function doAnother() {
console.log( another.join( " ! " ) );
}
return {
doSomething: doSomething,
doAnother: doAnother
};
}
var foo = CoolModule();
foo.doSomething(); // cool
foo.doAnother(); // 1 ! 2 ! 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment