Skip to content

Instantly share code, notes, and snippets.

@raix
Created April 12, 2013 23:08
Show Gist options
  • Save raix/5375913 to your computer and use it in GitHub Desktop.
Save raix/5375913 to your computer and use it in GitHub Desktop.
getNode('console.log')('Write this to the log...') Run a command from string - no eval used for this
getNode = function(string) {
var splitString = string.split('.');
var nodeThis = window;
// Divein nodeThis
if (splitString.length)
for (var i = 0; i < splitString.length-1; i++)
if (nodeThis)
nodeThis = nodeThis[splitString[i]];
// Get the last object
var func = (nodeThis)?nodeThis[splitString[splitString.length-1]]:undefined;
if (typeof(func) === "function")
return function( /* arguments */){
return func.apply(nodeThis, arguments);
};
return function() { return func; };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment