Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Created August 30, 2012 14:27
Show Gist options
  • Save vadviktor/3529610 to your computer and use it in GitHub Desktop.
Save vadviktor/3529610 to your computer and use it in GitHub Desktop.
Javascript: execute function by name
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