码迷,mamicode.com
首页 > 其他好文 > 详细

简洁表示对象

时间:2018-10-04 12:56:00      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:hello   ret   test   on()   span   属性   简写   arp   foo   

简洁表示对象

1.简写属性

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

const foo = ‘test‘;
const baz = { foo };
baz // {foo: "test"}

2.简写方法

const ss = {
    method() {
        return "Hello!";
    }
};
console.log(ss.method());
// 等同于
const ss2 = {
    method: function() {
        return "Hello!";
    }
};
console.log(ss2.method());

简洁表示对象

标签:hello   ret   test   on()   span   属性   简写   arp   foo   

原文地址:https://www.cnblogs.com/piaobodewu/p/9741993.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!