Skip to content

Commit f7d2edb

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-f830bc5d
2 parents b5f6b72 + f830bc5 commit f7d2edb

File tree

18 files changed

+61
-46
lines changed

18 files changed

+61
-46
lines changed

1-js/01-getting-started/1-intro/article.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Examples of such languages:
110110
- [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.
111111
- [Flow](http://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
112112
- [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.
113114

114115
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.
115116

1-js/02-first-steps/05-types/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const bigInt = 1234567890123456789012345678901234567890n;
8181

8282
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.
8383

84-
```smart header="Compatability issues"
84+
```smart header="Compatibility issues"
8585
Right now `BigInt` is supported in Firefox/Chrome/Edge, but not in Safari/IE.
8686
```
8787

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ So the code `a && b || c && d` is essentially the same as if the `&&` expression
224224
````
225225
226226
````warn header="Don't replace `if` with || or &&"
227-
Sometimes, people use the AND `&&` operator as a "shorter to write `if`".
227+
Sometimes, people use the AND `&&` operator as a "shorter way to write `if`".
228228
229229
For instance:
230230

1-js/05-data-types/04-array/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ An array is a special kind of object. The square brackets used to access a prope
193193

194194
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.
195195

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.
197197

198198
For instance, it is copied by reference:
199199

1-js/05-data-types/05-array-methods/6-calculator-extendable/_js.view/solution.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ function Calculator() {
1010
let split = str.split(' '),
1111
a = +split[0],
1212
op = split[1],
13-
b = +split[2]
13+
b = +split[2];
1414

1515
if (!this.methods[op] || isNaN(a) || isNaN(b)) {
1616
return NaN;
1717
}
1818

1919
return this.methods[op](a, b);
20-
}
20+
};
2121

2222
this.addMethod = function(name, func) {
2323
this.methods[name] = func;

1-js/05-data-types/11-date/1-new-date/solution.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ The `new Date` constructor uses the local time zone. So the only important thing
22

33
So February has number 1.
44

5+
Here's an example with numbers as date components:
6+
7+
```js run
8+
//new Date(year, month, date, hour, minute, second, millisecond)
9+
let d1 = new Date(2012, 1, 20, 3, 12);
10+
alert( d1 );
11+
```
12+
We could also create a date from a string, like this:
13+
514
```js run
6-
let d = new Date(2012, 1, 20, 3, 12);
7-
alert( d );
15+
//new Date(datastring)
16+
let d2 = new Date("February 20, 2012 03:12:00");
17+
alert( d2 );
818
```

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The global object provides variables and functions that are available anywhere.
55

66
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
77

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.
99

1010
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.
1111

@@ -81,7 +81,7 @@ if (!window.Promise) {
8181
That includes JavaScript built-ins, such as `Array` and environment-specific values, such as `window.innerHeight` -- the window height in the browser.
8282
- The global object has a universal name `globalThis`.
8383

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).
8585
- We should store values in the global object only if they're truly global for our project. And keep their number at minimum.
8686
- In-browser, unless we're using [modules](info:modules), global functions and variables declared with `var` become a property of the global object.
8787
- To make our code future-proof and easier to understand, we should access properties of the global object directly, as `window.x`.

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ alert(admin.fullName); // John Smith (*)
197197

198198
// setter triggers!
199199
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
200203
```
201204

202205
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.

2-ui/2-events/02-bubbling-and-capturing/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ When an event happens -- the most nested element where it happens gets labeled a
206206
207207
- 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}`).
208208
- 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}`.
210210
211211
Each handler can access `event` object properties:
212212
@@ -220,6 +220,6 @@ The capturing phase is used very rarely, usually we handle events on bubbling. A
220220
221221
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.
222222
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.
224224
225225
Bubbling and capturing lay the foundation for "event delegation" -- an extremely powerful event handling pattern that we study in the next chapter.

2-ui/2-events/05-dispatch-events/article.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ Any handler can listen for that event with `rabbit.addEventListener('hide',...)`
187187
<button onclick="hide()">Hide()</button>
188188

189189
<script>
190-
// hide() will be called automatically in 2 seconds
191190
function hide() {
192191
let event = new CustomEvent("hide", {
193192
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
211210

212211
## Events-in-events are synchronous
213212

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.
215214

216215
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.
217216

218217
For instance, in the code below the `menu-open` event is triggered during the `onclick`.
219218

220-
It's processed immediately, without waiting for `onlick` handler to end:
219+
It's processed immediately, without waiting for `onclick` handler to end:
221220

222221

223222
```html run autorun
@@ -243,7 +242,7 @@ The output order is: 1 -> nested -> 2.
243242

244243
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`).
245244

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.
247246

248247
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.
249248

@@ -283,9 +282,9 @@ Other constructors of native events like `MouseEvent`, `KeyboardEvent` and so on
283282

284283
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`.
285284

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.
287286

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.
289288

290289
Native events might be generated:
291290

0 commit comments

Comments
 (0)