Support use of `this` keyword in static ES6 methods
See original GitHub issueIt’s very common (and safe) to use the this
keyword in a static member definition:
class Foo {
static get baz() { return 'baz'; }
static bar() {
console.log(this.baz);
}
}
We should replace the this
keyword with a reference to the class name.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:20
- Comments:8 (6 by maintainers)
Top Results From Across the Web
static - JavaScript - MDN Web Docs - Mozilla
The static keyword defines a static method or property for a class, or a static initialization block (see the link for more information ......
Read more >Static Methods in ES6 - Medium
Note that for static methods, the this keyword references the class. You can call a static method from another static method within the...
Read more >JavaScript Static Methods
In ES6, you define static methods using the static keyword. The following example defines a static method called createAnonymous() for the Person class:....
Read more >Static properties and methods - The Modern JavaScript Tutorial
Usually, static methods are used to implement functions that belong to the class as a whole, but not to any particular object of...
Read more >javascript - ES6: this within static method - Stack Overflow
Under typical circumstances, the this in any call to something.method() will refer to something as long as the function is not an arrow ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Chiming in here to point out that using
this
within static es6 methods doesn’t throw an error at compile time, which is what I’d prefer for an unsupported feature (vs. breaking at runtime).It turns out that https://github.com/google/closure-compiler/commit/5b1e5316e5228d6d9f205e28440d67d9ec007f4b only fixes issues like https://github.com/google/closure-compiler/issues/2880 (unknown type of
this
), but the main problem (collapsing static methods) is still there.