Created
March 19, 2013 23:58
-
-
Save jmontross/5201250 to your computer and use it in GitHub Desktop.
javascript closure example
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
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