comunicationLeap/node_modules/component-bind/Readme.md
node_modules/component-bind/Readme.mdRaw
1# bind
2
3 Function binding utility.
4
5## Installation
6
7```
8$ component install component/bind
9```
10
11## API
12
13 - [bind(obj, fn)](#bindobj-fn)
14 - [bind(obj, fn, ...)](#bindobj-fn-)
15 - [bind(obj, name)](#bindobj-name)
16<a name=""></a>
17
18<a name="bindobj-fn"></a>
19### bind(obj, fn)
20should bind the function to the given object.
21
22```js
23var tobi = { name: 'tobi' };
24
25function name() {
26 return this.name;
27}
28
29var fn = bind(tobi, name);
30fn().should.equal('tobi');
31```
32
33<a name="bindobj-fn-"></a>
34### bind(obj, fn, ...)
35should curry the remaining arguments.
36
37```js
38function add(a, b) {
39 return a + b;
40}
41
42bind(null, add)(1, 2).should.equal(3);
43bind(null, add, 1)(2).should.equal(3);
44bind(null, add, 1, 2)().should.equal(3);
45```
46
47<a name="bindobj-name"></a>
48### bind(obj, name)
49should bind the method of the given name.
50
51```js
52var tobi = { name: 'tobi' };
53
54tobi.getName = function() {
55 return this.name;
56};
57
58var fn = bind(tobi, 'getName');
59fn().should.equal('tobi');
60```
61
62## License
63
64 MIT