租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

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