DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

ehmicky
ehmicky

Posted on

Wrap a JavaScript function without changing its name/properties (by sindresorhus)

Wrapping a JavaScript function is not as simple as one might think. Some of the issues you might encounter include:

  • keeping the original function name
  • keeping the original function static properties and inherited properties
  • showing the original function's body when using String(function)

mimic-fn is a small utility by sindresorhus tackling this issue.

https://github.com/sindresorhus/mimic-fn

Top comments (0)

🌚 Life is too short to browse without dark mode