ES6 对象扩展
Posted anthonyliu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ES6 对象扩展相关的知识,希望对你有一定的参考价值。
1.属性和方法的简写:
var foo = ‘bar‘; var baz = {foo}; console.log(baz); //{foo:‘bar‘}
ES6允许对象中只写属性名、不写属性值,属性值等于属性名表示的变量。
function f(x,y){ return {x,y}; } console.log(f(1,2)); //{ x: 1, y: 2 }
方法的简写:
var ms = {}; function getItem(){ } function setItem(){ } function clear(){ ms = {}; } module.exports = {getItem,setItem,clear}; //主要ES5中的getter和setter函数的写法。
以上是关于ES6 对象扩展的主要内容,如果未能解决你的问题,请参考以下文章