Norman's Note 諾曼筆記

Norman's Note 諾曼筆記

JavaScript ES6 技巧

Tagged templates

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Nullish coalescing operator (??)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator

How to conditionally add another object to an object?

https://stackoverflow.com/questions/11704267/in-javascript-how-to-conditionally-add-a-member-to-an-object

const a = {
  ...(someCondition && {b: 5})
}

export default 是 Anonymous 的,所以不可以 export default const xxx

為什麼 { ...'' } 在 Firefox console 會報錯?

  • 因為 Browser 把 {} 視為 block statement,而不是 object

https://bugzilla.mozilla.org/show_bug.cgi?id=972530