Skip to content

Instantly share code, notes, and snippets.

@mikemunsie
Created February 9, 2018 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemunsie/0aef057fc1e04784d682fb63fd6de9c3 to your computer and use it in GitHub Desktop.
Save mikemunsie/0aef057fc1e04784d682fb63fd6de9c3 to your computer and use it in GitHub Desktop.
Auto-Bind all methods in an es6 class
class MyClass {
constructor() {
Object.getOwnPropertyNames(this.constructor.prototype).forEach((m) => {
this[m] = this[m].bind(this)
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment