ES6 添加了一些很棒的功能,以便于更方便地定义对象。
//ES6前的做法:
const getMousePosition = (x, y) => ({
x: x,
y: y
});
//ES6 提供了一个语法糖,消除了类似x: x这种冗余的写法.你可以仅仅只写一次x,解释器会自动将其转换成x: x。下面是使用这种语法重写的同样的函数:
const getMousePosition = (x, y) => ({ x, y });
ES6 添加了一些很棒的功能,以便于更方便地定义对象。
//ES6前的做法:
const getMousePosition = (x, y) => ({
x: x,
y: y
});
//ES6 提供了一个语法糖,消除了类似x: x这种冗余的写法.你可以仅仅只写一次x,解释器会自动将其转换成x: x。下面是使用这种语法重写的同样的函数:
const getMousePosition = (x, y) => ({ x, y });