Created
May 6, 2015 20:35
-
-
Save mjackson/8a243823f20f16f792e1 to your computer and use it in GitHub Desktop.
A React.Component subclass that mimics 0.12's auto-binding behavior
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
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