Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

component-bind

component6.4m1.0.0

function binding utility

bind, utility

readme

bind

Function binding utility.

Installation

$ component install component/bind

API

bind(obj, fn)

should bind the function to the given object.

var tobi = { name: 'tobi' };

function name() {
  return this.name;
}

var fn = bind(tobi, name);
fn().should.equal('tobi');

bind(obj, fn, ...)

should curry the remaining arguments.

function add(a, b) {
  return a + b;
}

bind(null, add)(1, 2).should.equal(3);
bind(null, add, 1)(2).should.equal(3);
bind(null, add, 1, 2)().should.equal(3);

bind(obj, name)

should bind the method of the given name.

var tobi = { name: 'tobi' };

tobi.getName = function() {
  return this.name;
};

var fn = bind(tobi, 'getName');
fn().should.equal('tobi');

License

MIT

changelog

1.0.0 / 2014-05-27

  • index: use slice ref (#7, @viatropos)
  • package: rename package to "component-bind"
  • package: add "repository" field (#6, @repoify)
  • package: add "component" section

0.0.1 / 2010-01-03

  • Initial release