Skip to content

Instantly share code, notes, and snippets.

@jprivillaso
Last active October 1, 2017 16:24
Show Gist options
  • Save jprivillaso/59d81d7d5fe7cf1864fe05eb05d1eb4f to your computer and use it in GitHub Desktop.
Save jprivillaso/59d81d7d5fe7cf1864fe05eb05d1eb4f to your computer and use it in GitHub Desktop.
const DEFAULT_METHODS = ['constructor', 'render', 'componentDidMount', 'componentDidUpdate'];
class App extends React.Component {
constructor() {
super();
this.bindMethodsWithContext(this);
}
componentDidMount() {
//...
}
componentDidUpdate() {
//...
}
bindMethodsWithContext($this) {
Object.getOwnPropertyNames(App.prototype).forEach((func) => {
if (DEFAULT_METHODS.indexOf(func) === -1) {
$this[func] = $this[func].bind($this);
}
});
}
methodA() {
//...
}
methodB() {
//...
}
methodC() {
//...
}
render() {
//...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment