Skip to content

Instantly share code, notes, and snippets.

@wonderdogone
Forked from ironfroggy/autocomponent.jsx
Created November 25, 2015 18:25
Show Gist options
  • Save wonderdogone/fae6bec8158b8bb1b5b5 to your computer and use it in GitHub Desktop.
Save wonderdogone/fae6bec8158b8bb1b5b5 to your computer and use it in GitHub Desktop.
class AutoComponent extends React.Component {
constructor() {
super()
var cls = this.constructor
var methods, methodName
while (cls !== AutoComponent) {
methods = Object.getOwnPropertyNames(cls.prototype)
for (var i in methods) {
methodName = methods[i]
if (methodName.match(/^on[A-Z]/) !== null) {
this[methodName] = this[methodName].bind(this)
}
}
cls = cls.__proto__
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment