loading...

Discussion on: How to destructure a class instance without breaking "this" in JavaScript

Collapse
genspirit profile image
Genspirit

I believe you would have to do
this.strings = (strings = false) => {

but that would be a lot easier.

Collapse
xcs profile image
Buleandra Cristian

I am used to writing TypeScript, that arrow function syntax is valid TS class syntax, not really sure if it works natively in ES8.

Thread Thread
shailennaidoo profile image
Shailen Naidoo Author

It does work natively, I just preferred to use normal functions for this tutorial, maybe I could update it with an easier alternative with the arrow syntax. Arrow functions can be a bit ambiguous with this that's why i went with the other way

Thread Thread
shailennaidoo profile image
Shailen Naidoo Author

I am pretty sure that if you transpile your TS to target ES5 with that syntax it will just bind() the this in the output code, just need to test it 😄