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/03-code-quality/04-ninja-code/article.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ Instead, reuse existing names. Just write new values into them.
137
137
138
138
In a function try to use only variables passed as parameters.
139
139
140
-
That would make it really hard to identify what's exactly in the variable *now*. And also where it comes from. A person with weak intuition would have to analyze the code line-by-line and track the changes through every code branch.
140
+
That would make it really hard to identify what's exactly in the variable *now*. And also where it comes from. The purpose is to develop the intuition and memory of a person reading the code. A person with weak intuition would have to analyze the code line-by-line and track the changes through every code branch.
141
141
142
142
**An advanced variant of the approach is to covertly (!) replace the value with something alike in the middle of a loop or a function.**
143
143
@@ -155,7 +155,7 @@ function ninjaFunction(elem) {
155
155
156
156
A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code they will find out that they're working with a clone!
157
157
158
-
Seen in code regularly. Deadly effective even against an experienced ninja.
158
+
Seen in code regularly. Deadly effective even against an experienced ninja.
159
159
160
160
## Underscores for fun
161
161
@@ -169,8 +169,7 @@ A smart ninja puts underscores at one spot of code and evades them at other plac
169
169
170
170
Let everyone see how magnificent your entities are! Names like `superElement`, `megaFrame` and `niceItem` will definitely enlighten a reader.
171
171
172
-
Indeed, from one hand, something is written: `super..`, `mega..`, `nice..` But from the other hand -- that brings no details. A reader may decide to look for a hidden meaning and meditate for an hour or two.
173
-
172
+
Indeed, from one hand, something is written: `super..`, `mega..`, `nice..` But from the other hand -- that brings no details. A reader may decide to look for a hidden meaning and meditate for an hour or two of their paid working time.
174
173
175
174
176
175
## Overlap outer variables
@@ -180,7 +179,7 @@ When in the light, can't see anything in the darkness.<br>
180
179
When in the darkness, can see everything in the light.
181
180
```
182
181
183
-
Use same names for variables inside and outside a function. As simple. No efforts required.
182
+
Use same names for variables inside and outside a function. As simple. No efforts to invent new names.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/11-currying-partials/article.md
+10-15Lines changed: 10 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,7 +170,7 @@ To understand the benefits we definitely need a worthy real-life example.
170
170
171
171
Advanced currying allows the function to be both callable normally and partially.
172
172
173
-
For instance, we have the logging function `log(date, importance, message)` that formats and outputs the information. In real projects such functions also have many other useful features like sending logs over the network:
173
+
For instance, we have the logging function `log(date, importance, message)` that formats and outputs the information. In real projects such functions also have many other useful features like sending logs over the network, here we just use `alert`:
174
174
175
175
```js
176
176
functionlog(date, importance, message) {
@@ -184,34 +184,29 @@ Let's curry it!
184
184
log =_.curry(log);
185
185
```
186
186
187
-
After that `log` still works the normal way:
188
-
189
-
```js
190
-
log(newDate(), "DEBUG", "some debug");
191
-
```
192
-
193
-
...But also can be called in the curried form:
187
+
After that `log` work both the normal way and in the curried form:
Copy file name to clipboardExpand all lines: 1-js/11-async/07-microtask-queue/article.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ In-browser JavaScript execution flow, as well as Node.js, is based on an *event
58
58
59
59
"Event loop" is a process when the engine sleeps and waits for events. When they occur - handles them and sleeps again.
60
60
61
-
Events may come either comes from external sources, like user actions, or just as the end signal of an internal task.
61
+
Events may come either from external sources, like user actions, or just as the end signal of an internal task.
62
62
63
63
Examples of events:
64
64
-`mousemove`, a user moved their mouse.
@@ -124,7 +124,6 @@ Naturally, `promise` shows up first, because `setTimeout` macrotask awaits in th
124
124
125
125
As a logical consequence, macrotasks are handled only when promises give the engine a "free time". So if we have a chain of promise handlers that don't wait for anything, execute right one after another, then a `setTimeout` (or a user action handler) can never run in-between them.
126
126
127
-
128
127
## Unhandled rejection
129
128
130
129
Remember "unhandled rejection" event from the chapter <info:promise-error-handling>?
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...')`.
Copy file name to clipboardExpand all lines: 2-ui/5-loading/02-script-async-defer/article.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,8 +188,11 @@ But there are also essential differences between them:
188
188
|`defer`|*Document order* (as they go in the document). | Execute after the document is loaded and parsed (they wait if needed), right before `DOMContentLoaded`. |
189
189
190
190
```warn header="Page without scripts should be usable"
191
-
Please note that if you're using `defer`, then the page is visible before the script loads and enables all the graphical components.
191
+
Please note that if you're using `defer`, then the page is visible *before* the script loads.
192
192
193
-
So, buttons should be disabled by CSS or by other means, to let the user
193
+
So the user may read the page, but some graphical components are probably not ready yet.
194
+
195
+
There should be "loading" indication in proper places, not-working buttons disabled, to clearly show the user what's ready and what's not.
196
+
```
194
197
195
198
In practice, `defer` is used for scripts that need the whole DOM and/or their relative execution order is important. And `async` is used for independent scripts, like counters or ads. And their relative execution order does not matter.
0 commit comments