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/01-getting-started/1-intro/article.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,7 @@ Examples of such languages:
110
110
-[TypeScript](http://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
111
111
-[Flow](http://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
112
112
-[Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
113
+
-[Brython](https://brython.info/) is a Python transpiler to JavaScript that allow to write application in pure Python without JavaScript.
113
114
114
115
There are more. Of course, even if we use one of transpiled languages, we should also know JavaScript to really understand what we're doing.
As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter <info:bigint>. Read it when you need such big numbers.
83
83
84
-
```smart header="Compatability issues"
84
+
```smart header="Compatibility issues"
85
85
Right now `BigInt` is supported in Firefox/Chrome/Edge, but not in Safari/IE.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/04-array/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,7 +193,7 @@ An array is a special kind of object. The square brackets used to access a prope
193
193
194
194
They extend objects providing special methods to work with ordered collections of data and also the `length` property. But at the core it's still an object.
195
195
196
-
Remember, there are only 7 basic types in JavaScript. Array is an object and thus behaves like an object.
196
+
Remember, there are only eight basic data types in JavaScript (see the [Data types](https://javascript.info/types) chapter for more info). Array is an object and thus behaves like an object.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/05-global-object/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ The global object provides variables and functions that are available anywhere.
5
5
6
6
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
7
7
8
-
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. In some browsers, namely non-Chromium Edge, `globalThis` is not yet supported, but can be easily polyfilled.
8
+
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. It's supported in all major browsers.
9
9
10
10
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
11
11
@@ -81,7 +81,7 @@ if (!window.Promise) {
81
81
That includes JavaScript built-ins, such as `Array` and environment-specific values, such as `window.innerHeight` -- the window height in the browser.
82
82
- The global object has a universal name `globalThis`.
83
83
84
-
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js). As `globalThis` is a recent proposal, it's not supported in non-Chromium Edge (but can be polyfilled).
84
+
...But more often is referred by "old-school" environment-specific names, such as `window` (browser) and `global` (Node.js).
85
85
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
86
86
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
87
87
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/01-prototype-inheritance/article.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -197,6 +197,9 @@ alert(admin.fullName); // John Smith (*)
197
197
198
198
// setter triggers!
199
199
admin.fullName="Alice Cooper"; // (**)
200
+
201
+
alert(admin.fullName); // Alice Cooper , state of admin modified
202
+
alert(user.fullName); // John Smith , state of user protected
200
203
```
201
204
202
205
Here in the line `(*)` the property `admin.fullName` has a getter in the prototype `user`, so it is called. And in the line `(**)` the property has a setter in the prototype, so it is called.
Copy file name to clipboardExpand all lines: 2-ui/2-events/02-bubbling-and-capturing/article.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,7 +206,7 @@ When an event happens -- the most nested element where it happens gets labeled a
206
206
207
207
- Then the event moves down from the document root to `event.target`, calling handlers assigned with `addEventListener(..., true)` on the way (`true` is a shorthand for `{capture: true}`).
208
208
- Then handlers are called on the target element itself.
209
-
- Then the event bubbles up from `event.target` up to the root, calling handlers assigned using `on<event>` and `addEventListener` without the 3rd argument or with the 3rd argument `false/{capture:false}`.
209
+
- Then the event bubbles up from `event.target` to the root, calling handlers assigned using `on<event>` and `addEventListener` without the 3rd argument or with the 3rd argument `false/{capture:false}`.
210
210
211
211
Each handler can access `event` object properties:
212
212
@@ -220,6 +220,6 @@ The capturing phase is used very rarely, usually we handle events on bubbling. A
220
220
221
221
In real world, when an accident happens, local authorities react first. They know best the area where it happened. Then higher-level authorities if needed.
222
222
223
-
The same for event handlers. The code that set the handler on a particular element knows maximum details about the element and what it does. A handler on a particular `<td>` may be suited for that exactly `<td>`, it knows everything about it, so it should get the chance first. Then its immediate parent also knows about the context, but a little bit less, and so on till the very top element that handles general concepts and runs the last.
223
+
The same for event handlers. The code that set the handler on a particular element knows maximum details about the element and what it does. A handler on a particular `<td>` may be suited for that exactly `<td>`, it knows everything about it, so it should get the chance first. Then its immediate parent also knows about the context, but a little bit less, and so on till the very top element that handles general concepts and runs the last one.
224
224
225
225
Bubbling and capturing lay the foundation for "event delegation" -- an extremely powerful event handling pattern that we study in the next chapter.
Copy file name to clipboardExpand all lines: 2-ui/2-events/05-dispatch-events/article.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,6 @@ Any handler can listen for that event with `rabbit.addEventListener('hide',...)`
187
187
<buttononclick="hide()">Hide()</button>
188
188
189
189
<script>
190
-
// hide() will be called automatically in 2 seconds
191
190
functionhide() {
192
191
letevent=newCustomEvent("hide", {
193
192
cancelable:true// without that flag preventDefault doesn't work
@@ -211,13 +210,13 @@ Please note: the event must have the flag `cancelable: true`, otherwise the call
211
210
212
211
## Events-in-events are synchronous
213
212
214
-
Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then it's handing is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished.
213
+
Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then it's handling is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished.
215
214
216
215
The notable exception is when one event is initiated from within another one, e.g. using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed.
217
216
218
217
For instance, in the code below the `menu-open` event is triggered during the `onclick`.
219
218
220
-
It's processed immediately, without waiting for `onlick` handler to end:
219
+
It's processed immediately, without waiting for `onclick` handler to end:
221
220
222
221
223
222
```html run autorun
@@ -243,7 +242,7 @@ The output order is: 1 -> nested -> 2.
243
242
244
243
Please note that the nested event `menu-open` is caught on the `document`. The propagation and handling of the nested event is finished before the processing gets back to the outer code (`onclick`).
245
244
246
-
That's not only about `dispatchEvent`, there are other cases. If an event handler calls methods that trigger to other events -- they are too processed synchronously, in a nested fashion.
245
+
That's not only about `dispatchEvent`, there are other cases. If an event handler calls methods that trigger other events -- they too are processed synchronously, in a nested fashion.
247
246
248
247
Let's say we don't like it. We'd want `onclick` to be fully processed first, independently from `menu-open` or any other nested events.
249
248
@@ -283,9 +282,9 @@ Other constructors of native events like `MouseEvent`, `KeyboardEvent` and so on
283
282
284
283
For custom events we should use `CustomEvent` constructor. It has an additional option named `detail`, we should assign the event-specific data to it. Then all handlers can access it as `event.detail`.
285
284
286
-
Despite the technical possibility to generate browser events like `click` or `keydown`, we should use with the great care.
285
+
Despite the technical possibility of generating browser events like `click` or `keydown`, we should use them with great care.
287
286
288
-
We shouldn't generate browser events as it's a hacky way to run handlers. That's a bad architecture most of the time.
287
+
We shouldn't generate browser events as it's a hacky way to run handlers. That's bad architecture most of the time.
0 commit comments