|
1 | 1 |
|
2 | | -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() { // value є функцією |
11 | 11 | return Object.keys(this).join(); |
12 | 12 | } |
13 | 13 | } |
14 | 14 | }); |
15 | 15 | */!* |
16 | 16 |
|
17 | | -dictionary.apple = "Apple"; |
18 | | -dictionary.__proto__ = "test"; |
| 17 | +dictionary.apple = "Яблуко"; |
| 18 | +dictionary.__proto__ = "тест"; |
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. |
| 31 | +Продивіться розділ [](info:property-descriptors). |
0 commit comments