2016-06-11 89 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