Skip to content

Commit 28191e7

Browse files
committed
Russian-translate for for...of.md
1 parent 9f6aff9 commit 28191e7

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

docs/for...of.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### for...of
2-
A common error experienced by beginning JavaScript developers is that `for...in` for an array does not iterate over the array items. Instead it iterates over the *keys* of the object passed in. This is demonstrated in the below example. Here you would expect `9,2,5` but you get the indexes `0,1,2`:
2+
Распространенная ошибка, с которой сталкиваются начинающие JavaScript разработчики - это то, что `for...in` для массива не итерирует элементы массива. Вместо этого итерация происходит по *ключам* переданного объекта. Это показано на примере ниже. Здесь мы ожидаем `9,2,5`, но получаем индексы `0,1,2`:
33

44
```ts
55
var someArray = [9, 2, 5];
@@ -8,7 +8,7 @@ for (var item in someArray) {
88
}
99
```
1010

11-
This is one of the reasons why `for...of` exists in TypeScript (and ES6). The following iterates over the array correctly logging out the members as expected:
11+
Это первая причина, по которой `for...of` существует в TypeScript (и ES6). Следующая итерация массива корректно выводит члены массива как ожидалось:
1212

1313
```ts
1414
var someArray = [9, 2, 5];
@@ -17,7 +17,7 @@ for (var item of someArray) {
1717
}
1818
```
1919

20-
Similarly TypeScript has no trouble going through a string character by character using `for...of`:
20+
Точно также TypeScript не испытывает затруднений при итерировании строки посимвольно, используя `for...of`:
2121

2222
```ts
2323
var hello = "is it me you're looking for?";
@@ -26,36 +26,37 @@ for (var char of hello) {
2626
}
2727
```
2828

29-
#### JS Generation
30-
For pre ES6 targets TypeScript will generate the standard `for (var i = 0; i < list.length; i++)` kind of loop. For example here's what gets generated for our previous example:
29+
#### Генерация JS
30+
Для версий JS до ES6 TypeScript генерирует стандартный тип цикла `for (var i = 0; i < list.length; i++)`. Например, вот что генерируется для нашего предыдущего примера:
31+
3132
```ts
3233
var someArray = [9, 2, 5];
3334
for (var item of someArray) {
3435
console.log(item);
3536
}
3637

37-
// becomes //
38+
// становится //
3839

3940
for (var _i = 0; _i < someArray.length; _i++) {
4041
var item = someArray[_i];
4142
console.log(item);
4243
}
4344
```
44-
You can see that using `for...of` makes *intent* clearer and also decreases the amount of code you have to write (and variable names you need to come up with).
45+
Вы видите, что использование `for...of` делает код более понятным и уменьшает его объем.
4546

46-
#### Limitations
47-
If you are not targeting ES6 or above, the generated code assumes the property `length` exists on the object and that the object can be indexed via numbers e.g. `obj[2]`. So it is only supported on `string` and `array` for these legacy JS engines.
47+
#### Ограничения
48+
Для версий JS до ES6, сгенерированный код предполагает, что свойство `length` существует на объекте и этот объект может быть проиндексирован по номерам, например `obj[2]`. Это поддерживается только для строк и массивов для устаревших движков JS.
4849

49-
If TypeScript can see that you are not using an array or a string it will give you a clear error *"is not an array type or a string type"*;
50+
Если вы используете `for...of` не на массиве или строке, TypeScript сообщит об это ошибкой *"is not an array type or a string type"*.
5051
```ts
5152
let articleParagraphs = document.querySelectorAll("article > p");
52-
// Error: Nodelist is not an array type or a string type
53+
// Ошибка: Nodelist is not an array type or a string type
5354
for (let paragraph of articleParagraphs) {
5455
paragraph.classList.add("read");
5556
}
5657
```
5758

58-
Use `for...of` only for stuff that *you know* to be an array or a string. Note that this limitation might be removed in a future version of TypeScript.
59+
Используйте `for...of` только для случаев, когда *вы уверены*, что применяете это к строке или массиву. Помните, что это ограничение может быть удалено на следующих версиях TypeScript.
5960

60-
#### Summary
61-
You would be surprised at how many times you will be iterating over the elements of an array. The next time you find yourself doing that, give `for...of` a go. You might just make the next person who reviews your code happy.
61+
#### Заключение
62+
Вы можете удивиться, как часто вы итерируете элементы массива. В следующий раз, когда будете это делать, попробуйте использовать `for...of`. Вы можете просто порадовать следующего человека, который просматривает ваш код.

0 commit comments

Comments
 (0)