返回文章列表

ES6 Tricks Note

2017-12-04
1 分鐘
JavaScriptES6

ES6 Tricks

// Swap:
[a, b] = [b, a];

// Async/Await with Destructuring:
const [user, account] = await Promise.all([
  fetch('/user'),
  fetch('/account')
])

// Clone:
const obj = { ...oldObj }
const arr = [ ...oldArr ]

// Named parameters:
getStuffAwesome({ id: 150, force: true, verbose: true })

Related Reading

JavaScript hacks for ES6 hipsters — HackerNoon article exploring additional ES6 coding techniques and patterns.

原文發表於 Medium

Command Palette

Search for a command to run...