Skip to content

this is not pointing at instance of called class #10

@ghost

Description

this is not bound in created and destroyed, so it's hard to access custom context variables:

export class TestComponent extends Rete.Component {
  constructor(foo) {
    super("Test");
    this.foo = foo;
  }
  created(node) {
    console.log(`Created ${node.id} for ${this.foo}`); // Won't work, because `this` will be `undefined`
  }
}

The function hooks should be bound to the respective class instance.


Background

In my particular use-case, I'd like to have a context variable (equivalent to foo) point at a container DOM element and each node owns a DOM child that is attached to the container DOM element. However, during node creation / destruction I'm unable to find the container DOM element, because this is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions