Last active
August 29, 2015 14:13
-
-
Save justinAurand/c00c7459ac41057c1ad2 to your computer and use it in GitHub Desktop.
Scoping using a JavaScript module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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