This commit is contained in:
Ilya Kantor 2017-07-09 23:41:14 +03:00
parent d1cf45eda8
commit d32eabef0f
2 changed files with 6 additions and 4 deletions

View file

@ -271,7 +271,7 @@ So, we can set many properties at once.
## Object.getOwnPropertyDescriptors
To get many descriptors at once, we can use the method [Object.getOwnPropertyDescriptors(obj)](mdn:js/Object/getOwnPropertyDescriptors).
To get all property descriptors at once, we can use the method [Object.getOwnPropertyDescriptors(obj)](mdn:js/Object/getOwnPropertyDescriptors).
Together with `Object.defineProperties` it can be used as a "flags-aware" way of cloning an object:
@ -289,6 +289,8 @@ for(let key in user) {
...But that does not copy flags. So if we want a "better" clone then `Object.defineProperties` is preferred.
Another difference is that `for..in` ignores symbolic properties, but `Object.getOwnPropertyDescriptors` returns *all* property descriptors including symbolic ones.
## Sealing an object globally
Property descriptors work at the level of individual properties.