1. 程式人生 > >物件可計算屬性名(僅在ES6中)

物件可計算屬性名(僅在ES6中)

var suffix = ' name';
var person = { 
    ['first' + suffix]: 'Nicholas',
    ['last' + suffix]: 'Zakas'
}

person['first name']; // "Nicholas"
person['last name']; // "Zakas"