用工小程序前端代码
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.

56 lines
2.1 KiB

7 months ago
  1. # set-function-length <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. Set a function’s length.
  8. Arguments:
  9. - `fn`: the function
  10. - `length`: the new length. Must be an integer between 0 and 2**32.
  11. - `loose`: Optional. If true, and the length fails to be set, do not throw. Default false.
  12. Returns `fn`.
  13. ## Usage
  14. ```javascript
  15. var setFunctionLength = require('set-function-length');
  16. var assert = require('assert');
  17. function zero() {}
  18. function one(_) {}
  19. function two(_, __) {}
  20. assert.equal(zero.length, 0);
  21. assert.equal(one.length, 1);
  22. assert.equal(two.length, 2);
  23. assert.equal(setFunctionLength(zero, 10), zero);
  24. assert.equal(setFunctionLength(one, 11), one);
  25. assert.equal(setFunctionLength(two, 12), two);
  26. assert.equal(zero.length, 10);
  27. assert.equal(one.length, 11);
  28. assert.equal(two.length, 12);
  29. ```
  30. [package-url]: https://npmjs.org/package/set-function-length
  31. [npm-version-svg]: https://versionbadg.es/ljharb/set-function-length.svg
  32. [deps-svg]: https://david-dm.org/ljharb/set-function-length.svg
  33. [deps-url]: https://david-dm.org/ljharb/set-function-length
  34. [dev-deps-svg]: https://david-dm.org/ljharb/set-function-length/dev-status.svg
  35. [dev-deps-url]: https://david-dm.org/ljharb/set-function-length#info=devDependencies
  36. [npm-badge-png]: https://nodei.co/npm/set-function-length.png?downloads=true&stars=true
  37. [license-image]: https://img.shields.io/npm/l/set-function-length.svg
  38. [license-url]: LICENSE
  39. [downloads-image]: https://img.shields.io/npm/dm/set-function-length.svg
  40. [downloads-url]: https://npm-stat.com/charts.html?package=set-function-length
  41. [codecov-image]: https://codecov.io/gh/ljharb/set-function-length/branch/main/graphs/badge.svg
  42. [codecov-url]: https://app.codecov.io/gh/ljharb/set-function-length/
  43. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-function-length
  44. [actions-url]: https://github.com/ljharb/set-function-length/actions