bind-arguments
v1.0.0
Published
Bind context (optional) and multiple arguments to function.
Downloads
4
Readme
bind-arguments
Bind context (optional) and multiple arguments to function.
Install
npm i bind-arguments --save
Usage
For more use-cases see the tests
Params
<fn>
{Function} function for binding<args>
{Array} arguments to bind to givenfn
[ctx]
{Object} optional context for the return functionreturns
{Function} bound function
Example
var bindArguments = require('bind-arguments')
var args = ['foo', 'bar']
var ctx = {qux: 'baz'}
var boundFn = bindArguments(function (a, b, c) {
return [a, b, c, this.qux]
}, args, ctx)
boundFn() //=> ['foo', 'bar', undefined, 'baz']
var boundFn2 = bindArguments.call({qux: 'roo'}, function (a, b) {
return [a, b, this.qux]
}, args)
boundFn2() //=> ['foo', 'bar', 'roo']
Related
- array-slice: Array-slice method. Slices
array
from thestart
index up to, but not including, theend
index. - bind-context: Bind context to the given function and preserves her name. Or set new name of the given function. It also handles
.toString
correctly. - handle-arguments: Handles given Arguments object - return separatly last argument (commonly callback) and other arguments as Array. Useful in node-style callback flow.
- manage-arguments: Prevents arguments leakage - managing arguments. From Optimization killers by Petka Antonov.
- sliced: A faster Node.js alternative to Array.prototype.slice.call(arguments)
- useware: Accept Arguments object or multiple arguments that can be any value, including deeply nested arrays. Flatten the arguments/values then filter them to be only functions. Useful for
.use
methods. - useware-context: Much like
useware
but with the ability to bind given context to each function.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.