Skip to content

Instantly share code, notes, and snippets.

@mateuszkocz
Created September 20, 2013 11:57
Show Gist options
  • Save mateuszkocz/6636420 to your computer and use it in GitHub Desktop.
Save mateuszkocz/6636420 to your computer and use it in GitHub Desktop.
// Simple execution
window["functionName"](arguments);
// Nested exection.
window["My"]["Namespace"]["functionName"](arguments);
// Helper function.
function executeFunctionByName(functionName, context /*, args */) {
var args = Array.prototype.slice.call(arguments).splice(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(this, args);
}
executeFunctionByName("My.Namespace.functionName", window, arguments);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment