Skip to content

Instantly share code, notes, and snippets.

@justinAurand
Last active August 29, 2015 14:13
Show Gist options
  • Save justinAurand/c00c7459ac41057c1ad2 to your computer and use it in GitHub Desktop.
Save justinAurand/c00c7459ac41057c1ad2 to your computer and use it in GitHub Desktop.
Scoping using a JavaScript module.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Module</title>
</head>
<body>
<div id="messenger">null</div>
</body>
<script>
var MessageModule = (function () {
var message = 'Taco';
var pluralize = function (string) {
return string + 's';
};
var getMessage = function () {
return pluralize(message);
};
return {
getMessage: getMessage
};
})();
var MessageModuleExtender = (function (MessageModule) {
MessageModule.getModifiedMessage = function () {
return MessageModule.getMessage() + ', yum!';
};
return MessageModule;
})(MessageModule || {});
var outputElement = document.getElementById('messenger');
outputElement.innerHTML = MessageModule.getModifiedMessage();
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment