es6 属性的简洁表示法

function f(x, y) {
  return {x, y};
}
// 等同于
function f(x, y) {
  return {x: x, y: y};
}
f(1, 2) // Object {x: 1, y: 2}
const o = {
  method() {
    return "Hello!";
  }
};
// 等同于
const o = {
  method: function() {
    return "Hello!";
  }
};

 

posted @ 2020-03-24 18:57  banzhuxiang  阅读(152)  评论(0)    收藏  举报