Bind and partially apply with memoization


stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
31Jan 20, 2017Apr 4, 2016Minified + gzip package size for @dlmanning/bind in KB



bind(self, fn)BoundFunction

bind a function to the provided context

BoundFunction : function

Kind: global interface

Name Type
partial function

boundFunction.partial ⇒ BoundFunction

Perform a partial application of the provided parameters. The returned function is memoized for a given set of parameters, so that repeated applications will always return the same function object.

Kind: instance property of BoundFunction
Returns: BoundFunction - another BoundFunction with the provided params applied

Param Type Description
[...params] * zero or more items to partially apply


const applied = boundMethod.partial('Hello', 'World')
// applied is a BoundFunction which will always be called with "Hello" and
// "World" as its first two params

bind(self, fn) ⇒ BoundFunction

bind a function to the provided context

Kind: global function
Returns: BoundFunction - a bound function

Param Type Description
self Object context to which the function will be bound
fn function function to be bound


var boundMethod = bind(this, this.aMethod)
boundMethod() // boundMethod is bound to this

bind.all(self, methods) ⇒ Object.<string, BoundFunction>

bind a collection of functions to the provided context.

Kind: static method of bind

Param Type Description
self Object context to which the function will be bound
methods Array.<string> | Object.<string, function()> If an array is given, it must be an array of strings whose names are methods on the provided context object. If an object is provided, the returned object will key the bound functions according to those provided.


// assumes hear, see and speak are methods on this
bind.all(this, ['hear', 'see', 'speak'])
// or you can pass an object with function values, which will be bound to this
bind.all(this, { hear: function1, see: function2, speak: function3 })

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.