I recently developed an "anonymous" class inspired by this insightful discussion on Typescript anonymous classes.
However, I'm facing a challenge in accessing the outer scope members. Here's a snippet of my code for context:
class BaseCounter {
counter = 1;
count() {
console.log(++this.counter);
}
getDoubleCounter() {
return new class DoubleCounter extends BaseCounter {
count() {
// In Java, we can access the outer scope counter using ClassName.this
// like: BaseCounter.this.counter += 2
// console.log(BaseCounter.this.counter);
}
}();
}