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