Comment

Comment by bramen

There's already a proposal for field declarations, where you can do the following:

  class Foo {
    bar = () => {
      console.log(this);
    }
  }
This basically puts `this.bar = () => console.log(this)` in the constructor, and since it's an arrow function it captures the correct context.

See https://github.com/tc39/proposal-class-fields.

parent bramen 9 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton