Ohm-Management - Projektarbeit B-ME
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.

readme.md 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # mimic-fn [![Build Status](https://travis-ci.org/sindresorhus/mimic-fn.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-fn)
  2. > Make a function mimic another one
  3. Useful when you wrap a function in another function and like to preserve the original name and other properties.
  4. ## Install
  5. ```
  6. $ npm install mimic-fn
  7. ```
  8. ## Usage
  9. ```js
  10. const mimicFn = require('mimic-fn');
  11. function foo() {}
  12. foo.unicorn = '🦄';
  13. function wrapper() {
  14. return foo() {};
  15. }
  16. console.log(wrapper.name);
  17. //=> 'wrapper'
  18. mimicFn(wrapper, foo);
  19. console.log(wrapper.name);
  20. //=> 'foo'
  21. console.log(wrapper.unicorn);
  22. //=> '🦄'
  23. ```
  24. ## API
  25. It will copy over the properties `name`, `length`, `displayName`, and any custom properties you may have set.
  26. ### mimicFn(to, from)
  27. It will modify `to` and return it.
  28. #### to
  29. Type: `Function`
  30. Mimicking function.
  31. #### from
  32. Type: `Function`
  33. Function to mimic.
  34. ## Related
  35. - [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
  36. ## License
  37. MIT © [Sindre Sorhus](https://sindresorhus.com)