3

Stumbled upon this code:

const { operator } = this;

from https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L89

What does it mean?

0

1 Answer 1

4

It's object destructuring. This

const { operator, other } = this;

is equivalent to

const operator = this.operator;
const other = this.other;

It's borrowed from ES6, which has the same feature.

Sign up to request clarification or add additional context in comments.

3 Comments

Is there any reason to not just write const operator = this.operator;?
Not really, and in this case I think it'd be more readable to do it the normal way. Maybe the author just wanted to play with new features!
@AlexeyVagarenko If you need to get properties from this, you will need to write mutiple lines about fetch. Thereforce, ES6 offers destructuring is easy to write in one line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.