Created
January 26, 2021 10:14
-
-
Save ProofOfPizza/d90bac7d560f0619a427cf831286a517 to your computer and use it in GitHub Desktop.
autobind typescript
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
function Autobind(_: any, __: any, descriptor: PropertyDescriptor): PropertyDescriptor { | |
const oldMethod = descriptor.value; | |
const newMethod: PropertyDescriptor = { | |
configurable: true, | |
enumerable: false, | |
get() { | |
const boundFn = oldMethod.bind(this); | |
return boundFn; | |
}, | |
}; | |
return newMethod; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment