Skip to content

Instantly share code, notes, and snippets.

@greduan
Created May 13, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greduan/27f5e275b4a321895075 to your computer and use it in GitHub Desktop.
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
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