Created
February 9, 2018 03:50
-
-
Save mikemunsie/0aef057fc1e04784d682fb63fd6de9c3 to your computer and use it in GitHub Desktop.
Auto-Bind all methods in an es6 class
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
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