Created
April 12, 2013 23:08
-
-
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
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
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