This all makes me remember the bad days of bind and bindAll and such and how I never ever have to think about this problem anymore and it’s just wonderful.
Can’t remember the last time I saw a ‘this’. Functional programming forever!
Can’t remember the last time I saw a ‘this’. Functional programming forever!
class Foo {
thisCouldBeAnything() {return this}
thisIsDefinitelyFoo = () => this
}
new Foo().thisCouldBeAnything.call('use me')
// 'use me'
new Foo().thisIsDefinitelyFoo.call('unused')
// Foo
Since the intention is often to keep `this` to refer to the class, people have been binding every single method in the class constructor, but this is no longer necessary thanks to arrow functions.I tried to have a base class with a default serializer method and bam, right back to binding problems.