Skip to content

Instantly share code, notes, and snippets.

@chriscorwin
Created June 10, 2014 14:12
Show Gist options
  • Select an option

  • Save chriscorwin/8d84e94b199e1b09d24f to your computer and use it in GitHub Desktop.

Select an option

Save chriscorwin/8d84e94b199e1b09d24f to your computer and use it in GitHub Desktop.
/**
* Executes a function by name.
*/
var executeFunctionByName = function executeFunctionByName(functionName, context /*, args */ ) {
var args = Array.prototype.slice.call(arguments, 2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for (var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(context, args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment