You can use it when you want to wrap a function in another function and want to preserve the original name and properties.
$ npm install mimicking-func
const mimickingFunc = require('mimicking-func');
const say = ()=> {};
say.hello = 'hello';
say.hi = 'hi';
function wrapperFunction() {
return say() {};
}
console.log(wrapperFunction.name);
//=> 'wrapper'
mimicFn(wrapperFunction, say);
console.log(wrapperFunction.name);
//=> 'foo'
console.log(wrapperFunction.say);
//=> '
Will copy over the properties :
name
length
displayName
and other custom properties you have declared.
It will modify to
and return it.
Type: Function
Mimicking function.
Type: Function
Function to mimic.
- rename-fn - Rename a function
MIT ©