Created
July 2, 2011 17:30
-
-
Save JoeyButler/1061411 to your computer and use it in GitHub Desktop.
Example of dynamically creating functions in javascript.
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 funcs = ['functionOne', 'functionTwo', 'functionThree']; | |
for(func in funcs) { | |
(function (func_name) { | |
window[func_name] = function () { | |
console.log('My name is ' + func_name); | |
} | |
})(funcs[func]); | |
} | |
functionOne(); | |
functionTwo(); | |
functionThree(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment