Skip to content

This and super binding inside initializers #6

@jridgewell

Description

@jridgewell
class Base {
    x = 1;
    method() { return 2; }
}

class Sub extends Base {
    z = this.x + super.method();
    constructor() {
      const instance = Reflect.construct(Base, [], new.target);
      new.initialize(instance);
      return instance;
    }
}

const instance = new Sub();
console.log(instance.z)

Just so that we're thinking about it. The this binding should be easy, but I'm not 100% sure how to change the super binding? Does it just work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions