Skip to content

Instantly share code, notes, and snippets.

@jmontross
Created March 19, 2013 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmontross/5201250 to your computer and use it in GitHub Desktop.
Save jmontross/5201250 to your computer and use it in GitHub Desktop.
javascript closure example
var addMultipleGameKeysModule = (function () {
var iGameKey;
function getGameKeys() {
var gameKeyList = [];
$j("input'[name*='GAMEKEY']").each(function(i){
gameKeyList.push($j(this).val());
});
return gameKeyList;
}
function injectGameKeys() {
var gameKeyList = getGameKeys();
$j("#edtGameKeyList").val(gameKeyList.join(','));
}
return { // <----- this starts the object being returned when this module function executes
init: function () {
injectGameKeys();
// I have access to injectGameKeys & getGameKeys & iGameKey
} // init
}; // <----- this ends the object being returned when this module function executes
})();
document.observe('dom:loaded',addMultipleGameKeysModule.init);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment