|
1 |
| -# call-bind |
| 1 | +# call-bind <sup>[![Version Badge][npm-version-svg]][package-url]</sup> |
| 2 | + |
| 3 | +[![github actions][actions-image]][actions-url] |
| 4 | +[![coverage][codecov-image]][codecov-url] |
| 5 | +[![dependency status][deps-svg]][deps-url] |
| 6 | +[![dev dependency status][dev-deps-svg]][dev-deps-url] |
| 7 | +[![License][license-image]][license-url] |
| 8 | +[![Downloads][downloads-image]][downloads-url] |
| 9 | + |
| 10 | +[![npm badge][npm-badge-png]][package-url] |
| 11 | + |
2 | 12 | Robustly `.call.bind()` a function.
|
| 13 | + |
| 14 | +## Getting started |
| 15 | + |
| 16 | +```sh |
| 17 | +npm install --save call-bind |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage/Examples |
| 21 | + |
| 22 | +```js |
| 23 | +const assert = require('assert'); |
| 24 | +const callBind = require('call-bind'); |
| 25 | +const callBound = require('call-bind/callBound'); |
| 26 | + |
| 27 | +function f(a, b) { |
| 28 | + assert.equal(this, 1); |
| 29 | + assert.equal(a, 2); |
| 30 | + assert.equal(b, 3); |
| 31 | + assert.equal(arguments.length, 2); |
| 32 | +} |
| 33 | + |
| 34 | +const fBound = callBind(f); |
| 35 | + |
| 36 | +const slice = callBound('Array.prototype.slice'); |
| 37 | + |
| 38 | +delete Function.prototype.call; |
| 39 | +delete Function.prototype.bind; |
| 40 | + |
| 41 | +fBound(1, 2, 3); |
| 42 | + |
| 43 | +assert.deepEqual(slice([1, 2, 3, 4], 1, -1), [2, 3]); |
| 44 | +``` |
| 45 | + |
| 46 | +## Tests |
| 47 | + |
| 48 | +Clone the repo, `npm install`, and run `npm test` |
| 49 | + |
| 50 | +[package-url]: https://npmjs.org/package/call-bind |
| 51 | +[npm-version-svg]: https://versionbadg.es/ljharb/call-bind.svg |
| 52 | +[deps-svg]: https://david-dm.org/ljharb/call-bind.svg |
| 53 | +[deps-url]: https://david-dm.org/ljharb/call-bind |
| 54 | +[dev-deps-svg]: https://david-dm.org/ljharb/call-bind/dev-status.svg |
| 55 | +[dev-deps-url]: https://david-dm.org/ljharb/call-bind#info=devDependencies |
| 56 | +[npm-badge-png]: https://nodei.co/npm/call-bind.png?downloads=true&stars=true |
| 57 | +[license-image]: https://img.shields.io/npm/l/call-bind.svg |
| 58 | +[license-url]: LICENSE |
| 59 | +[downloads-image]: https://img.shields.io/npm/dm/call-bind.svg |
| 60 | +[downloads-url]: https://npm-stat.com/charts.html?package=call-bind |
| 61 | +[codecov-image]: https://codecov.io/gh/ljharb/call-bind/branch/main/graphs/badge.svg |
| 62 | +[codecov-url]: https://app.codecov.io/gh/ljharb/call-bind/ |
| 63 | +[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/call-bind |
| 64 | +[actions-url]: https://github.com/ljharb/call-bind/actions |
0 commit comments