3 ms·
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
by Waterluvian 5y ago
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!
- dimmke 5y agoSeriously. It feels like an entire area of JavaScript I pretty much never wade into anymore.
- SilurianWenlock 5y agoWhy not?
- schwartzworld 5y agoNew features were added to the language that make this sort of stuff unecessary.
- cunthorpe 5y agoUntechnically speaking: Arrow functions preserve the `this` in their declaration point, whereas regular functions change `this` if they're called as methods. 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.
- cmpolis 5y agoThis sparked my memory of using "var self = this;" and "var _this = this;" Can't put my finger on it, but _this_ seems quite funny looking back on it (not to say it didn't work...)
- quickthrower2 5y agoI use this… but in classes in typescript and I’m quite happy to do so.
- Waterluvian 5y agoI’ve tried to use classes in TS and they’re just so weak that I always regret it. I tried to have a base class with a default serializer method and bam, right back to binding problems.