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