Question
I would like to deconstruct an object similar to this
const {header, content} = this.data
where data has
data: {header: ‘some header’, content: ‘some content’}
to a class attribute so I can call
this.header or this.content
anywhere in the class.
What I have tried
I was assuming it would be something like this
{this.header, this.content} = this.data
or
this {header, content} = this.data
but both throw errors.
Conclusion
Is it even possible to deconstruct assign directly to class properties?
You can do it with destructuring, because the target of a destructuring assignment can be just about anything you can assign to, but it doesn’t really buy you much:
({header : this.header, content: this.content} = data);
(Parens are only needed so the { doesn’t look like the start of a block.)
Live Example: