Special `this` binding in class methods

I'd like to ask about this specific case:

Would it be possible to get the this binding to be different than what is apparent, i.e bound at the moment of call it seems, and rebind it to class instance. Or new keyword, say @@instance?

No.

You probably want to write either

class Mar {
  constructor() {
    this.sym = Symbol("sym");
    this[this.sym] = function*() { … };
  }
}

or

const sym = Symbol("sym");
class Mar {
  static sym = sym
  *[sym]() { … }
}

although it is still unclear what you are actually trying to achieve.

1 Like