Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active July 17, 2018 13:08
Show Gist options
  • Save VitorLuizC/6ee5bd45ea65c7d63168d70ff432c75b to your computer and use it in GitHub Desktop.
Save VitorLuizC/6ee5bd45ea65c7d63168d70ff432c75b to your computer and use it in GitHub Desktop.
import reconstruct, { PropertyName } from 'reconstruct-descriptors';
/**
* Check if object property is a method.
*/
function isMethod (name: PropertyName, value: any) {
return (
typeof value === 'function' &&
typeof name !== 'symbol' &&
name !== 'constructor'
);
}
export default <T extends object>(object: T) => reconstruct(object, (name, { value }) => {
return isMethod(name, value) && {
[property]: {
value () {
return (instance) => value.apply(instance, arguments);
},
writable: true,
enumerable: true,
configurable: true
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment