Skip to content

Instantly share code, notes, and snippets.

@JasonDeving
Created March 13, 2016 05:01
Show Gist options
  • Save JasonDeving/1e653ebfdae9dbb5b688 to your computer and use it in GitHub Desktop.
Save JasonDeving/1e653ebfdae9dbb5b688 to your computer and use it in GitHub Desktop.
javascript revealing module pattern
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
window.onload = function () {
calculator.add(2,2);
calculator.subtract(2,2);
}
</script>
</head>
<body>
<div id="Output"></div>
<script>
//calculator.js
var calculator = function (eq) {
// private members
var eqCtl = document.getElementById(eq),
add = function(x,y) {
eqCtl.innerHTML = x + y;
},
subtract = function(x, y) {
alert(x - y);
}
//public members
return {
add: add,
subtract: subtract
}
}('Output');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment