Created
May 16, 2017 12:45
-
-
Save sznowicki/c076c52a0242c77a3044f4a79e9af4c3 to your computer and use it in GitHub Desktop.
ES6 lost "this" scope when method is assigned to a variable
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
class Foo { | |
static bar() { | |
return 'bar'; | |
} | |
baz() { | |
return this.constructor.bar(); | |
} | |
} | |
const foo = new Foo(); | |
foo.baz(); // works fine | |
const baz = foo.baz; | |
baz(); // TypeError: Cannot read property 'constructor' of undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment