Last active
January 28, 2017 22:45
-
-
Save aackerman/11758f80444945a9226c4bbd2199d45c to your computer and use it in GitHub Desktop.
Autobind
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
const autobind = (instance) => { | |
for (var prop in instance) { | |
if (instance.hasOwnProperty(property) && typeof instance[property] === 'function') { | |
instance[property] = instance[property].bind(instance) | |
} | |
} | |
} |
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
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