ES6 允许直接写入变量和函数,作为对象的属性和方法。这样的书写更加简洁。

let 
    name = 'Pirates of the Caribbean',
    index = 5,
    captain = {
        primary : 'Jack Sparrow',
        secondary : 'Borbossa'
    };

let film = {
    name,
    index,
    captain,
    desc(){
        console.log(this.name + ' ' + this.index);
    }
}

 

相关文章: