Skip to content

Instantly share code, notes, and snippets.

@aackerman
Last active January 28, 2017 22:45
Show Gist options
  • Save aackerman/11758f80444945a9226c4bbd2199d45c to your computer and use it in GitHub Desktop.
Save aackerman/11758f80444945a9226c4bbd2199d45c to your computer and use it in GitHub Desktop.
Autobind
const autobind = (instance) => {
for (var prop in instance) {
if (instance.hasOwnProperty(property) && typeof instance[property] === 'function') {
instance[property] = instance[property].bind(instance)
}
}
}
const React = require('react')
const { Component } = React
const autobind = require('./autobind')
class A extends Component {
constructor() {
super()
autobind(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment