2016-06-11 157 views

回答

4

這是object destructuring。這

const { operator, other } = this; 

相當於

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

它從ES6,其中有the same feature借來的。

+0

是否有任何理由不只是寫'const operator = this.operator;'? –

+0

不是,在這種情況下,我認爲以正常方式進行操作會更具可讀性。也許作者只是想玩新功能! – Nick

+0

@AlexeyVagarenko如果您需要從'this'獲取屬性,您需要編寫關於獲取的多行信息。因此,ES6提供「解構」很容易在一行中編寫。 – Tony