Created
August 30, 2012 14:27
-
-
Save vadviktor/3529610 to your computer and use it in GitHub Desktop.
Javascript: execute function by name
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
executeFunctionByName = function(functionName) | |
{ | |
var args = Array.prototype.slice.call(arguments).slice(1); | |
var namespaces = functionName.split("."); | |
var func = namespaces.pop(); | |
var ns = namespaces.join('.'); | |
if(ns === undefined || ns === '') | |
{ | |
ns = 'window'; | |
} | |
ns = eval(ns); | |
return ns[func].apply(ns, args); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment