Skip to content

Instantly share code, notes, and snippets.

@JoeyButler
Created July 2, 2011 17:30
Show Gist options
  • Save JoeyButler/1061411 to your computer and use it in GitHub Desktop.
Save JoeyButler/1061411 to your computer and use it in GitHub Desktop.
Example of dynamically creating functions in javascript.
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