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
The method can take all enumerable keys using `Object.keys`and output their list.
2
+
В методе можно получить список всех перечисляем ключей с помощью `Object.keys`и вывести их как список.
3
3
4
-
To make`toString`non-enumerable, let's define it using a property descriptor. The syntax of `Object.create`allows us to provide an object with property descriptors as the second argument.
4
+
Чтобы сделать`toString`не перечисляемым, давайте определим метод как дескриптор свойства. Синтаксис `Object.create`позволяет нам добавить в объект дескрипторы свойств как второй аргумент.
5
5
6
6
```js run
7
7
*!*
8
8
let dictionary =Object.create(null, {
9
-
toString: { //define toString property
10
-
value() { //the value is a function
9
+
toString: { //определяем свойство toString
10
+
value() { //значение -- это функция
11
11
returnObject.keys(this).join();
12
12
}
13
13
}
@@ -17,15 +17,15 @@ let dictionary = Object.create(null, {
17
17
dictionary.apple="Apple";
18
18
dictionary.__proto__="test";
19
19
20
-
// apple and __proto__ is in the loop
20
+
// apple и __proto__ выведены в цикле
21
21
for(let key in dictionary) {
22
-
alert(key); // "apple", then "__proto__"
22
+
alert(key); // "apple", затем "__proto__"
23
23
}
24
24
25
-
//comma-separated list of properties by toString
25
+
//список свойств разделённых запятой выведен с помощью toString
26
26
alert(dictionary); // "apple,__proto__"
27
27
```
28
28
29
-
When we create a property using a descriptor, its flags are `false` by default. So in the code above,`dictionary.toString`is non-enumerable.
29
+
Когда мы создаем свойство с помощью дескриптора, все флаги по умолчанию имеют значение `false`. Таким образом, в коде выше`dictionary.toString`не перечисляемое свойство.
30
30
31
-
See the the chapter [](info:property-descriptors)for review.
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/04-prototype-methods/2-dictionary-tostring/task.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,30 +2,30 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Add toString to the dictionary
5
+
# Добавьте toString в словарь
6
6
7
-
There's an object `dictionary`, created as `Object.create(null)`, to store any `key/value` pairs.
7
+
Имеется объект `dictionary`, созданный с помощью `Object.create(null)` для хранения любых пар `ключ/значение`.
8
8
9
-
Add method `dictionary.toString()` into it, that should return a comma-delimited list of keys. Your`toString`should not show up in `for..in` over the object.
9
+
Добавьте ему метод `dictionary.toString()`, который должен возвращать список ключей разделенных запятой. Ваш`toString`не должен выводиться при итерации объекта с помощью цикла `for..in`.
10
10
11
-
Here's how it should work:
11
+
Вот так это должно работать:
12
12
13
13
```js
14
14
let dictionary =Object.create(null);
15
15
16
16
*!*
17
-
//your code to add dictionary.toString method
17
+
//ваш код для добавляет метод dictionary.toString
18
18
*/!*
19
19
20
-
//add some data
20
+
//добавляем немного данных
21
21
dictionary.apple="Apple";
22
-
dictionary.__proto__="test"; // __proto__ is a regular property key here
22
+
dictionary.__proto__="test"; //здесь __proto__ -- это обычный ключ
0 commit comments