Skip to content

Instantly share code, notes, and snippets.

@codefuncode
Forked from ricardoalcocer/snippet.html
Created December 3, 2020 23:53
Show Gist options
  • Save codefuncode/6668111453245ffe3f5c9ec8c2ebe994 to your computer and use it in GitHub Desktop.
Save codefuncode/6668111453245ffe3f5c9ec8c2ebe994 to your computer and use it in GitHub Desktop.
JS Closure Snippet
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script lang="javascript">
var module = function(){
var theArray = [];
return{
loader : function(){
theArray[0] = function() { console.log("first function"); }
theArray[1] = function() { console.log("second function"); }
theArray[2] = function() { console.log("third function"); }
},
getData : function(id){
theArray[id]();
}
}
}();
module.loader();
module.getData(0);
module.getData(1);
module.getData(2);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment