Created
March 4, 2010 01:13
-
-
Save efleming969/321288 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
<script type="text/javascript"> | |
var thingy = (function() { | |
var aPrivateVariable = "foo"; | |
function aPrivateFunction(val) { | |
console.log("a private function:"+val); | |
aPrivateVariable = val; | |
} | |
// export an object from closure | |
return { | |
aPublicFunction1: function() { | |
console.log("a public function 1") | |
aPrivateFunction("foo"); | |
}, | |
aPublicFunction2: function() { | |
console.log("a public function 2") | |
console.log(aPrivateVariable) | |
} | |
} | |
})(); | |
</script> | |
</head> | |
<body> | |
<button onclick="thingy.aPublicFunction1();">Public Function 1</button> | |
<button onclick="thingy.aPublicFunction2();">Public Function 2</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment