Skip to content

Commit 95731e7

Browse files
authored
Translate the article. Vol. 2
1 parent ca2abc1 commit 95731e7

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

  • 1-js/06-advanced-functions/05-global-object

1-js/06-advanced-functions/05-global-object/article.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,44 @@ alert("Hello");
1414
window.alert("Hello");
1515
```
1616

17-
We can reference other built-in functions like `Array` as `window.Array` and create our own properties on it.
17+
Мы можем ссылаться на другие встроенные функции типа `Array` как `window.Array` или создавать свои собственные свойства глобального объекта. We can reference other built-in functions like `Array` as `window.Array` and create our own properties on it.
1818

19-
## Browser: the "window" object
19+
## Браузер: объект "window" Browser: the "window" object
2020

21-
For historical reasons, in-browser `window` object is a bit messed up.
21+
По историческим причинам, браузерный объект `window` выглядит слегка запутанно. For historical reasons, in-browser `window` object is a bit messed up.
2222

23-
1. It provides the "browser window" functionality, besides playing the role of a global object.
23+
1. Он предоставляет инструменты для работы с окном браузера, а также играет роль глобального объекта. It provides the "browser window" functionality, besides playing the role of a global object.
2424

25-
We can use `window` to access properties and methods, specific to the browser window:
25+
Мы можем использовать `window` для доступа к свойствам и методам характерным для окна браузера. We can use `window` to access properties and methods, specific to the browser window:
2626

2727
```js run
28-
alert(window.innerHeight); // shows the browser window height
28+
alert(window.innerHeight); // выводит высоту окна браузера shows the browser window height
2929

30-
window.open('http://google.com'); // opens a new browser window
30+
window.open('http://google.com'); // открывает новое окно браузера opens a new browser window
3131
```
3232

33-
2. Top-level `var` variables and function declarations automatically become properties of `window`.
33+
2. Если переменные, объявленные с помощью `var` или декларации функиций находятся на верхнем уровне программы, то они автоматически становятся свойствами `window`. Top-level `var` variables and function declarations automatically become properties of `window`.
3434

35-
For instance:
35+
Например For instance:
3636
```js untrusted run no-strict refresh
3737
var x = 5;
3838

39-
alert(window.x); // 5 (var x becomes a property of window)
39+
alert(window.x); // 5 (var x становиться свойством window) 5 (var x becomes a property of window)
4040

4141
window.x = 0;
4242

43-
alert(x); // 0, variable modified
43+
alert(x); // 0, переменная изменена variable modified
4444
```
4545

46-
Please note, that doesn't happen with more modern `let/const` declarations:
46+
Обратите внимание, что этого не происходит с более современными `let/const` объявлениями. Please note, that doesn't happen with more modern `let/const` declarations:
4747

4848
```js untrusted run no-strict refresh
4949
let x = 5;
5050

51-
alert(window.x); // undefined ("let" doesn't create a window property)
51+
alert(window.x); // undefined ("let" не создаёт свойства window) undefined ("let" doesn't create a window property)
5252
```
5353

54-
3. Also, all scripts share the same global scope, so variables declared in one `<script>` become visible in another ones:
54+
3. Кроме того, все скрипты имеют общюю глобальную область видимотси, поэтому переменные, объявленные в одном теге `<script>` становятся видимыми в других. Also, all scripts share the same global scope, so variables declared in one `<script>` become visible in another ones:
5555

5656
```html run
5757
<script>
@@ -65,21 +65,21 @@ For historical reasons, in-browser `window` object is a bit messed up.
6565
</script>
6666
```
6767

68-
4. And, a minor thing, but still: the value of `this` in the global scope is `window`.
68+
4. Мелочь, но всё же, значение `this` в глобальной области видимости — `window`. And, a minor thing, but still: the value of `this` in the global scope is `window`.
6969

7070
```js untrusted run no-strict refresh
7171
alert(this); // window
7272
```
7373

74-
Why was it made like this? At the time of the language creation, the idea to merge multiple aspects into a single `window` object was to "make things simple". But since then many things changed. Tiny scripts became big applications that require proper architecture.
74+
Почему было сделано так? На момент создания языка, объединение нескольких аспектов в одном объекте `window`, должно было "упростить" работу. Но с тех пор многое изменилось. Крошечные скрипты превратились в крупные приложения, требующие правльной архитектуры. Why was it made like this? At the time of the language creation, the idea to merge multiple aspects into a single `window` object was to "make things simple". But since then many things changed. Tiny scripts became big applications that require proper architecture.
7575

76-
Is it good that different scripts (possibly from different sources) see variables of each other?
76+
Хорошо ли, что разные скрипты (возможно из разных источников) "видят" переменные друг друга? Is it good that different scripts (possibly from different sources) see variables of each other?
7777

78-
No, it's not, because it may lead to naming conflicts: the same variable name can be used in two scripts for different purposes, so they will conflict with each other.
78+
Нет, потому что это может привести к конфликту имён: одинаковые имена переменных могут использоваться двумя скриптами для различных целей и эти переменные будут конфликтовать между собой. No, it's not, because it may lead to naming conflicts: the same variable name can be used in two scripts for different purposes, so they will conflict with each other.
7979

80-
As of now, the multi-purpose `window` is considered a design mistake in the language.
80+
Сейчас, многоцелевой `window` считается ошибкой проектирования языка. As of now, the multi-purpose `window` is considered a design mistake in the language.
8181

82-
Luckily, there's a "road out of hell", called "JavaScript modules".
82+
К счастью, есть "дорога из ада" — JavaScript модули. Luckily, there's a "road out of hell", called "JavaScript modules".
8383

8484
If we set `type="module"` attribute on a `<script>` tag, then such script is considered a separate "module" with its own top-level scope (lexical environment), not interfering with `window`.
8585

0 commit comments

Comments
 (0)