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
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/03-strict-mode/article.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,9 +53,17 @@ alert("some code");
53
53
54
54
Иногда, когда `use strict` имеет значение, вы можете получить неправильные результаты.
55
55
56
-
Даже если мы нажмём `key:Shift+Enter` для ввода нескольких строк и напишем вверху `use strict` -- это не сработает. Это связано с тем, как консоль выполняет код внутри.
56
+
Можно использовать `key:Shift+Enter` для ввода нескольких строк и написать вверху `use strict`:
57
57
58
-
Надёжный способ сделать так, чтобы `use strict` заработал, это ввести код в консоль следующим образом:
58
+
```js
59
+
'use strict'; <Shift+Enter для перехода на новую строку>
60
+
// ...ваш код...
61
+
<Enter для запуска>
62
+
```
63
+
64
+
В большинстве браузеров, включая Chrome и Firefox, это работает.
65
+
66
+
В старых браузерах консоль не учитывает такой `use strict`, там можно "оборачивать" код в функцию, вот так:
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/11-currying-partials/article.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -169,7 +169,7 @@ function curry(f) {
169
169
170
170
Продвинутое каррирование позволяет вызывать функцию, как обычно, так и с частичным применением.
171
171
172
-
Например, у нас есть функция логирования `log(date, importance, message)`, которая форматирует и выводит информацию. В реальных проектах у таких функций есть много других полезных возможностей, например, посылать логи по сети:
172
+
Например, у нас есть функция логирования `log(date, importance, message)`, которая форматирует и выводит информацию. В реальных проектах у таких функций есть много других полезных возможностей, например, посылать логи по сети, здесь для простоты используем `alert`:
Copy file name to clipboardExpand all lines: 2-ui/1-document/08-styles-and-classes/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,10 +66,10 @@ So we can operate both on the full class string using `className` or on individu
66
66
Methods of `classList`:
67
67
68
68
-`elem.classList.add/remove("class")` -- adds/removes the class.
69
-
-`elem.classList.toggle("class")` -- if the class exists, then removes it, otherwise adds it.
69
+
-`elem.classList.toggle("class")` -- adds the class if it doesn't exist, otherwise removes it.
70
70
-`elem.classList.contains("class")` -- returns `true/false`, checks for the given class.
71
71
72
-
Besides that, `classList` is iterable, so we can list all classes like this:
72
+
Besides, `classList` is iterable, so we can list all classes with `for..of`, like this:
73
73
74
74
```html run
75
75
<bodyclass="main page">
@@ -147,7 +147,7 @@ To set the full style as a string, there's a special property `style.cssText`:
147
147
</script>
148
148
```
149
149
150
-
We rarely use it, because such assignment removes all existing styles: it does not add, but replaces them. May occasionally delete something needed. But still can be done for new elements when we know we won't delete something important.
150
+
This property is rarely used, because such assignment removes all existing styles: it does not add, but replaces them. May occasionally delete something needed. But we can safely use it for new elements, when we know we won't delete an existing style.
151
151
152
152
The same can be accomplished by setting an attribute: `div.setAttribute('style', 'color: red...')`.
|`defer`|*Порядок документа* (как расположены в документе). | Выполняется после того, как документ загружен и обработан (ждёт), непосредственно перед `DOMContentLoaded`. |
189
189
190
190
```warn header="Страница без скриптов должна быть рабочей"
191
-
Пожалуйста, помните, что когда вы используете `defer`, страница видна до того, как скрипт загрузится и подключит все графические компоненты.
191
+
Пожалуйста, помните, что когда вы используете `defer`, страница видна до того, как скрипт загрузится.
192
192
193
-
Поэтому кнопки должны быть отключены с помощью CSS или другим образом.
193
+
Пользователь может знакомиться с содержимым страницы, читать её, но графические компоненты пока отключены.
194
194
195
-
На практике `defer` используется для скриптов, которым требуется доступ ко всему DOM и/или важен их относительный порядок выполнения.
195
+
Поэтому обязательно должна быть индикация загрузки, нерабочие кнопки - отключены с помощью CSS или другим образом. Чтобы пользователь явно видел, что уже готово, а что пока нет.
196
+
```
196
197
198
+
На практике `defer` используется для скриптов, которым требуется доступ ко всему DOM и/или важен их относительный порядок выполнения.
197
199
198
-
А `async` используется для независимых скриптов, например счётчиков и рекламы, относительный порядок выполнения которых не играет роли.
200
+
А `async`хорош для независимых скриптов, например счётчиков и рекламы, относительный порядок выполнения которых не играет роли.
Generally, what's inside the lookaround (a common name for both lookahead and lookbehind) parentheses does not become a part of the match.
62
62
63
-
E.g. in the pattern `pattern:\d+(?!€)`, the `pattern:€` sign doesn't get captured as a part of the match.
63
+
E.g. in the pattern `pattern:\d+(?=€)`, the `pattern:€` sign doesn't get captured as a part of the match. That's natural: we look for a number `pattern:\d+`, while `pattern:(?=€)` is just a test that it should be followed by `subject:€`.
64
64
65
-
But if we want to capture the whole lookaround expression or a part of it, that's possible. Just need to wrap that into additional parentheses.
65
+
But in some situations we might want to capture the lookaround expression as well, or a part of it. That's possible. Just wrap that into additional parentheses.
66
66
67
67
For instance, here the currency `pattern:(€|kr)` is captured, along with the amount:
68
68
@@ -89,9 +89,13 @@ Usually parentheses are numbered left-to-right, but lookbehind is an exception,
89
89
90
90
## Summary
91
91
92
-
Lookahead and lookbehind (commonly referred to as "lookaround") are useful for simple regular expressions, when we'd like not to take something into the match depending on the context before/after it.
92
+
Lookahead and lookbehind (commonly referred to as "lookaround") are useful when we'd like to take something into the match depending on the context before/after it.
93
93
94
-
Sometimes we can do the same manually, that is: match all and filter by context in the loop. Remember, `str.matchAll` and `reg.exec` return matches with `.index` property, so we know where exactly in the text it is. But generally regular expressions can do it better.
94
+
For simple regexps we can do the similar thing manually. That is: match everything, in any context, and then filter by context in the loop.
95
+
96
+
Remember, `str.matchAll` and `reg.exec` return matches with `.index` property, so we know where exactly in the text it is, and can check the context.
97
+
98
+
But generally regular expressions are more convenient.
95
99
96
100
Lookaround types:
97
101
@@ -102,4 +106,4 @@ Lookaround types:
102
106
|`pattern:(?<=y)x`| Positive lookbehind |`x` if after `y`|
103
107
|`pattern:(?<!y)x`| Negative lookbehind |`x` if not after `y`|
104
108
105
-
Lookahead can also used to disable backtracking. Why that may be needed -- see in the next chapter.
109
+
Lookahead can also used to disable backtracking. Why that may be needed and other details -- see in the next chapter.
0 commit comments