0.0.2 • Published 5 years ago

mimicking-func v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

mimicking-func

You can use it when you want to wrap a function in another function and want to preserve the original name and properties.

Install

$ npm install mimicking-func

Usage

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);
//=> '

API

Will copy over the properties : name length displayName and other custom properties you have declared.

mimickingFunc(to, from)

It will modify to and return it.

to

Type: Function

Mimicking function.

from

Type: Function

Function to mimic.

Related

License

MIT ©