Created
March 13, 2016 05:01
-
-
Save JasonDeving/1e653ebfdae9dbb5b688 to your computer and use it in GitHub Desktop.
javascript revealing module pattern
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>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