diff --git a/1-js/07-object-oriented-programming/01-property-descriptors/article.md b/1-js/07-object-oriented-programming/01-property-descriptors/article.md index bda88d41..e927d5d7 100644 --- a/1-js/07-object-oriented-programming/01-property-descriptors/article.md +++ b/1-js/07-object-oriented-programming/01-property-descriptors/article.md @@ -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. diff --git a/1-js/07-object-oriented-programming/06-prototype-methods/article.md b/1-js/07-object-oriented-programming/06-prototype-methods/article.md index ec14fd48..1e423eeb 100644 --- a/1-js/07-object-oriented-programming/06-prototype-methods/article.md +++ b/1-js/07-object-oriented-programming/06-prototype-methods/article.md @@ -51,14 +51,14 @@ alert(rabbit.jumps); // true The descriptors are in the same format as described in the chapter . -We can use `Object.create` to perform a full object cloning, like this: +We can use `Object.create` to perform an object cloning more powerful than copying properties in `for..in`: ```js // fully identical shallow clone of obj -let clone = Object.create(obj, Object.getOwnPropertyDescriptors(obj)); +let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj)); ``` -This call makes a truly exact copy of `obj`, including all properties: enumerable and non-enumerable, data properties and setters/getters -- everything, and with the right `[[Prototype]]`. But not an in-depth copy of course. +This call makes a truly exact copy of `obj`, including all properties: enumerable and non-enumerable, data properties and setters/getters -- everything, and with the right `[[Prototype]]`. ## Brief history