3
在此代码迷迷糊糊:这是什么打字稿语法?
const { operator } = this;
从https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L89
是什么意思?
在此代码迷迷糊糊:这是什么打字稿语法?
const { operator } = this;
从https://github.com/ReactiveX/rxjs/blob/master/src/Observable.ts#L89
是什么意思?
const { operator, other } = this;
相当于
const operator = this.operator;
const other = this.other;
它从ES6,其中有the same feature借来的。
是否有任何理由不只是写'const operator = this.operator;'? –
不是,在这种情况下,我认为以正常方式进行操作会更具可读性。也许作者只是想玩新功能! – Nick
@AlexeyVagarenko如果您需要从'this'获取属性,您需要编写关于获取的多行信息。因此,ES6提供“解构”很容易在一行中编写。 – Tony