Using Symbol to Add Object Property
If we want to add Object property at runtime, it chanced that we override property of original Object. Since Symbol is a unique value, using Symbol Property to prevent property from overriding.
If we want to add Object property at runtime, it chanced that we override property of original Object. Since Symbol is a unique value, using Symbol Property to prevent property from overriding.
If we only allow limited values for arguments, using Enums is a good choice. Unfortunately, we don’t have native Enums in JavaScript, but we can use Object and Symbol to simulate it.
Symbol is a new type for unique value in ECMAScript 2015.
ECMAScript 2015 introduced Array.prototype.entries, which returns index and element from Array.
If we want to get key and value from Object simultaneously, we used to use Object.keys to get all keys, and then use [] with the key to get value. Now we can use Object.entries to get key and value at once.
Object Destructuring was introduced by ECMAScript 2015. Using it with function argument, we can implement Pass By Name feature in ECMAScript.
當 ECMAScript 2015 引進 Promise 概念後,實務上會遇到 Array Promise,若要搭配 ECMAScript 2017 的 async await,可使用 for await of 讓 Codebase 更精簡。
實務上較少刪除 Object 的 Property,但若真的想刪除 Property,ECMAScript 提供了兩種方法。
若想取得 Object 的 Property 做運算,但又不確定 Object 是否包含此 Property 時,ECMAScript 提供多種方式可判斷 Property 是否存在。
Array.prototype.reduce 只能接受傳入 Synchronous Function,若要傳入 Asynchronous Function,可依需求使用不同方式實現。