Readme.md (983B)
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) 20 should bind the function to the given object. 21 22 ```js 23 var tobi = { name: 'tobi' }; 24 25 function name() { 26 return this.name; 27 } 28 29 var fn = bind(tobi, name); 30 fn().should.equal('tobi'); 31 ``` 32 33 <a name="bindobj-fn-"></a> 34 ### bind(obj, fn, ...) 35 should curry the remaining arguments. 36 37 ```js 38 function add(a, b) { 39 return a + b; 40 } 41 42 bind(null, add)(1, 2).should.equal(3); 43 bind(null, add, 1)(2).should.equal(3); 44 bind(null, add, 1, 2)().should.equal(3); 45 ``` 46 47 <a name="bindobj-name"></a> 48 ### bind(obj, name) 49 should bind the method of the given name. 50 51 ```js 52 var tobi = { name: 'tobi' }; 53 54 tobi.getName = function() { 55 return this.name; 56 }; 57 58 var fn = bind(tobi, 'getName'); 59 fn().should.equal('tobi'); 60 ``` 61 62 ## License 63 64 MIT