aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/component-bind/Readme.md
blob: 6a8febc8a314eac0592ded590a2e26fb5a5b6a90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# bind

  Function binding utility.

## Installation

```
$ component install component/bind
```

## API

   - [bind(obj, fn)](#bindobj-fn)
   - [bind(obj, fn, ...)](#bindobj-fn-)
   - [bind(obj, name)](#bindobj-name)
<a name=""></a>
 
<a name="bindobj-fn"></a>
### bind(obj, fn)
should bind the function to the given object.

```js
var tobi = { name: 'tobi' };

function name() {
  return this.name;
}

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

<a name="bindobj-fn-"></a>
### bind(obj, fn, ...)
should curry the remaining arguments.

```js
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);
```

<a name="bindobj-name"></a>
### bind(obj, name)
should bind the method of the given name.

```js
var tobi = { name: 'tobi' };

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

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

## License 

  MIT