Skip to content

Instantly share code, notes, and snippets.

@mjackson
Created May 6, 2015 20:35
Show Gist options
  • Save mjackson/8a243823f20f16f792e1 to your computer and use it in GitHub Desktop.
Save mjackson/8a243823f20f16f792e1 to your computer and use it in GitHub Desktop.
A React.Component subclass that mimics 0.12's auto-binding behavior
var React = require('react');
class AutoBindingComponent extends React.Component {
constructor(props) {
super(props);
for (var property in this) {
if (this.hasOwnProperty(property) && typeof this[property] === 'function') {
this[property] = this[property].bind(this);
}
}
}
}
module.exports = AutoBindingComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment