Fork me on GitHub

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

Coding Poineer

ES6 不常见的语法糖

语法糖:官方内置封装的一些快捷操作

场景:判断属性是否存在

const target = obj.person ? obj.person.name : '' 语法糖: obj.person?.name

场景:对象的属性key字符串想要用表达式给出
var obj = {
  ['a'+'b'] : 'aaas',
  ['c'.repeat(5)] : 'two'
}
// {ab: "aaas", ccccc: "two"}
posted @ 2021-08-18 16:09  365/24/60  阅读(57)  评论(0编辑  收藏  举报