Created
May 13, 2015 21:52
-
-
Save greduan/27f5e275b4a321895075 to your computer and use it in GitHub Desktop.
extrapolates a method from an object from string, so 'boop.bap' gets called from the provided context with the provided params
This file contains hidden or 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
var callFuncFromString = function (funcString, context, params) { | |
// funcString should be a string like so 'boop.bap', no () at the end | |
// parameters should be an array of the func's parameters, for .apply() | |
var layers = funcString.split('.') | |
layers.forEach(function (val) { | |
context = context[val] | |
}) | |
return context.apply(this, params) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment