ES6 - 简化对象写法

ES6 允许在大括号里面,直接写入变量和函数,作为对象的属性和方法。 这些的书写更加简洁。

 

let name  = "Alan";

let play = function(){

  console.log("We want to play with you")

}


const friend = {
  name,  // ES5: name:name,
  play, // ES5: play:function(){}
  improve(){// ES5:improve: function(){}
    console.log(" we want to play with you and your friends")
  }

}

 

posted @ 2021-03-01 14:38  鑫仔Alan  阅读(100)  评论(0编辑  收藏  举报