You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modern methods to setup and directly access the prototype are:
176
+
Современные способы установки и прямого доступа к прототипу это:
177
177
178
-
-[Object.create(proto[, descriptors])](mdn:js/Object/create) -- creates an empty object with given `proto` as `[[Prototype]]` (can be`null`) and optional property descriptors.
179
-
-[Object.getPrototypeOf(obj)](mdn:js/Object.getPrototypeOf) -- returns the`[[Prototype]]`of`obj` (same as `__proto__` getter).
180
-
-[Object.setPrototypeOf(obj, proto)](mdn:js/Object.setPrototypeOf) -- sets the`[[Prototype]]`of`obj`to`proto` (same as `__proto__` setter).
178
+
-[Object.create(proto[, descriptors])](mdn:js/Object/create) -- создает пустой объект со свойством `[[Prototype]]`, указанным как `proto` (может быть`null`), и необязательными дескрипторами свойств.
179
+
-[Object.getPrototypeOf(obj)](mdn:js/Object.getPrototypeOf) -- возвращает свойство`[[Prototype]]`объекта`obj` (то же самое что и геттер `__proto__`).
180
+
-[Object.setPrototypeOf(obj, proto)](mdn:js/Object.setPrototypeOf) -- устанавливает свойство`[[Prototype]]`объекта`obj`как`proto` (то же самое что и сеттер `__proto__`).
181
181
182
-
The built-in `__proto__` getter/setter is unsafe if we'd want to put user-generated keys in to an object. Just because a user may enter "__proto__" as the key, and there'll be an error with hopefully easy, but generally unpredictable consequences.
182
+
Встроенный геттер/сеттер __proto__ не безопасен, если мы хотим использовать *созданные пользователями* ключи в объекте. Как минимум потому, что пользователь может ввести "proto" как ключ, от чего может возникнуть ошибка. Если повезет - последствия будут легкими, но обычно они непредсказуемы.
183
183
184
-
So we can either use`Object.create(null)`to create a "very plain" object without `__proto__`, or stick to`Map` objects for that.
184
+
Тогда мы можем использовать либо`Object.create(null)`для создания "очень пустого" объекта, либо использовать коллекцию`Map`.
185
185
186
-
Also, `Object.create`provides an easy way to shallow-copy an object with all descriptors:
186
+
Также, `Object.create`дает нам легкий способ создать поверхностную копию объекты со всеми дескрипторами:
187
187
188
188
```js
189
189
let clone =Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
190
190
```
191
191
192
192
193
-
-[Object.keys(obj)](mdn:js/Object/keys) / [Object.values(obj)](mdn:js/Object/values) / [Object.entries(obj)](mdn:js/Object/entries) -- returns an array of enumerable own string property names/values/key-value pairs.
194
-
-[Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) -- returns an array of all own symbolic property names.
195
-
-[Object.getOwnPropertyNames(obj)](mdn:js/Object/getOwnPropertyNames) -- returns an array of all own string property names.
196
-
-[Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) -- returns an array of all own property names.
197
-
-[obj.hasOwnProperty(key)](mdn:js/Object/hasOwnProperty): it returns `true` if `obj`has its own (not inherited) property named`key`.
193
+
-[Object.keys(obj)](mdn:js/Object/keys) / [Object.values(obj)](mdn:js/Object/values) / [Object.entries(obj)](mdn:js/Object/entries) -- возвращают массив всех перечисляемых собственных строковых имен/значений/пар ключ-значение.
194
+
-[Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) -- возвращает массив всех собственных имен-символов свойств.
195
+
-[Object.getOwnPropertyNames(obj)](mdn:js/Object/getOwnPropertyNames) -- возвращает массив всех собственных строковых имен свойств.
196
+
-[Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) -- возвращает массив всех собственных имен свойств.
197
+
-[obj.hasOwnProperty(key)](mdn:js/Object/hasOwnProperty): возвращает `true`, если у `obj`есть собственное (не унаследованное) свойство с именем`key`.
198
198
199
-
We also made it clear that`__proto__`is a getter/setter for `[[Prototype]]`and resides in `Object.prototype`, just as other methods.
199
+
Мы также ясно указали, что `__proto__`-- это геттер/сеттер для свойства `[[Prototype]]`и находится он в `Object.prototype`, как и другие методы.
200
200
201
-
We can create an object without a prototype by `Object.create(null)`. Such objects are used as "pure dictionaries", they have no issues with `"__proto__"`as the key.
201
+
Мы можем создавать объекты без прототипов с помощью `Object.create(null)`. Такие объекты можно использовать как "чистые словари", у них нет проблем с использованием строки `"__proto__"`как ключ.
202
202
203
-
All methods that return object properties (like `Object.keys`and others) -- return "own" properties. If we want inherited ones, then we can use`for..in`.
203
+
Все методы, которые возвращают свойства объектов (такие как `Object.keys`и другие), возвращают "собственные" свойства. Если мы хотим получить унаследованные, тогда мы можем использовать цикл`for..in`.
0 commit comments