Skip to content

Instantly share code, notes, and snippets.

@sznowicki
Created May 16, 2017 12:45
Show Gist options
  • Save sznowicki/c076c52a0242c77a3044f4a79e9af4c3 to your computer and use it in GitHub Desktop.
Save sznowicki/c076c52a0242c77a3044f4a79e9af4c3 to your computer and use it in GitHub Desktop.
ES6 lost "this" scope when method is assigned to a variable
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