Created
October 30, 2016 09:17
-
-
Save dhrrgn/3595754600c3587b221d731985e7b1ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Bind in constructor | |
class BindInConstructor { | |
constructor() { | |
this.foo = this.foo.bind(this); | |
this.bar = this.bar.bind(this); | |
} | |
foo() { | |
this.bar(); | |
} | |
bar() { | |
console.log('Hello'); | |
} | |
} | |
// Bind at call time | |
class BindAtCallTime { | |
foo() { | |
this.bar.call(this); | |
} | |
bar() { | |
console.log('Hello'); | |
} | |
} | |
// Use class properties and arrow functions | |
class ClassPropertiesArrowFunctions { | |
foo = () => { | |
this.bar(); | |
}; | |
bar = () => { | |
console.log('Hello'); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment