Promise.allSettled

This commit is contained in:
Ilya Kantor 2019-06-18 10:02:03 +03:00
parent 027933531e
commit d7f90176c7
16 changed files with 191 additions and 253 deletions

View file

@ -74,7 +74,9 @@ alert(id.description); // id
Symbols allow us to create "hidden" properties of an object, that no other part of code can occasionally access or overwrite.
For instance, if we'd like to add an "identifier" to the object `user`, we can use a symbol as a key for it:
For instance, if we're working with `user` objects, that come from a third-party code and don't have any `id` field. We'd like to add identifiers to them.
Let's use a symbol key for it:
```js run
let user = { name: "John" };
@ -86,9 +88,9 @@ alert( user[id] ); // we can access the data using the symbol as the key
What's the benefit of using `Symbol("id")` over a string `"id"`?
Let's make the example a bit deeper to see that.
As `user` objects come from another code, and that code works with them, we shouldn't just add any fields to it. That's unsafe.
Imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so thes scripts are completely unaware of each other.
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
Then that script can create its own `Symbol("id")`, like this: