Skip to content

Instantly share code, notes, and snippets.

@ProofOfPizza
Created January 26, 2021 10:14
Show Gist options
  • Save ProofOfPizza/d90bac7d560f0619a427cf831286a517 to your computer and use it in GitHub Desktop.
Save ProofOfPizza/d90bac7d560f0619a427cf831286a517 to your computer and use it in GitHub Desktop.
autobind typescript
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