Skip to content

Instantly share code, notes, and snippets.

@dotproto
Last active Aug 29, 2015
Embed
What would you like to do?
Function application as a service
function buildApply() {
var args = Array.prototype.slice.call(arguments, 0);
var fn = args.shift();
// proxy function
return function bindProxy() {
var proxyArgs = Array.prototype.slice.call(arguments, 0);
return fn.apply(null, args.concat(proxyArgs));
}
}
@dotproto

This comment has been minimized.

Copy link
Owner Author

@dotproto dotproto commented Dec 10, 2014

Use case is partial application in a scenario where your target function requires access to params it wouldn't otherwise have access to.

foo.asyncMethod(key)
      .then( buildApply(proxiedMethod, biz, bazz) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment