Skip to content

Instantly share code, notes, and snippets.

@dotproto
Last active February 14, 2024 01:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotproto/34e38e29d78b19c1ab96 to your computer and use it in GitHub Desktop.
Save dotproto/34e38e29d78b19c1ab96 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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