Last active
July 17, 2018 13:08
-
-
Save VitorLuizC/6ee5bd45ea65c7d63168d70ff432c75b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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