Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Last active August 29, 2015 14:15
Show Gist options
  • Save pr00thmatic/fa02632d188bab6e4bcd to your computer and use it in GitHub Desktop.
Save pr00thmatic/fa02632d188bab6e4bcd to your computer and use it in GitHub Desktop.
var dog = (function () {
// execution context: dog's module
var nombre = "dog";
var setName = function (newName) {
nombre = newName;
};
var speak = function () {
console.log('[' + nombre + ']: woof!');
};
return {
// execution context: dog (the actually returned dog)
setName : setName,
speak : speak
};
})();
dog.speak(); // [dog]: woof!
dog.setName('Shipo');
dog.speak(); // [Shipo]: woof!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment