Skip to content

Commit a1254b7

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-4d654318
2 parents ee5eaa1 + 4d65431 commit a1254b7

File tree

15 files changed

+98
-97
lines changed

15 files changed

+98
-97
lines changed

Diff for: 1-js/02-first-steps/04-variables/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ In other words, capital-named constants are only used as aliases for "hard-coded
290290
291291
Talking about variables, there's one more extremely important thing.
292292
293-
A variable name should have a clean, obvious meaning, describe the data that it stores.
293+
A variable name should have a clean, obvious meaning, describing the data that it stores.
294294
295295
Variable naming is one of the most important and complex skills in programming. A quick glance at variable names can reveal which code was written by a beginner versus an experienced developer.
296296

Diff for: 1-js/04-object-basics/06-constructor-new/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Usually, constructors do not have a `return` statement. Their task is to write a
136136

137137
But if there is a `return` statement, then the rule is simple:
138138

139-
- If `return` is called with object, then it is returned instead of `this`.
139+
- If `return` is called with an object, then the object is returned instead of `this`.
140140
- If `return` is called with a primitive, it's ignored.
141141

142142
In other words, `return` with an object returns that object, in all other cases `this` is returned.

Diff for: 1-js/07-object-properties/02-property-accessors/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ There's no similar method to handle deletion of an accessor property. Only gette
102102
103103
## Accessor descriptors
104104
105-
Descriptors for accessor properties are different -- as compared with data properties.
105+
Descriptors for accessor properties are different from those for data properties.
106106
107-
For accessor properties, there is no `value` and `writable`, but instead there are `get` and `set` functions.
107+
For accessor properties, there is no `value` or `writable`, but instead there are `get` and `set` functions.
108108
109109
That is, an accessor descriptor may have:
110110

Diff for: 1-js/08-prototypes/03-native-prototypes/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ So, generally, modifying a native prototype is considered a bad idea.
129129

130130
**In modern programming, there is only one case where modifying native prototypes is approved. That's polyfilling.**
131131

132-
Polyfilling is a term for making a substitute for a method that exists in JavaScript specification, but not yet supported by current JavaScript engine.
132+
Polyfilling is a term for making a substitute for a method that exists in JavaScript specification, but is not yet supported by current JavaScript engine.
133133

134134
Then we may implement it manually and populate the built-in prototype with it.
135135

Diff for: 1-js/08-prototypes/04-prototype-methods/article.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Why so?
7272
That's for historical reasons.
7373

7474
- The `"prototype"` property of a constructor function works since very ancient times.
75-
- Later in the year 2012: `Object.create` appeared in the standard. It allowed to create objects with the given prototype, but did not allow to get/set it. So browsers implemented non-standard `__proto__` accessor that allowed to get/set a prototype at any time.
76-
- Later in the year 2015: `Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is optional for non-browser environments.
75+
- Later, in the year 2012: `Object.create` appeared in the standard. It allowed to create objects with the given prototype, but did not allow to get/set it. So browsers implemented non-standard `__proto__` accessor that allowed to get/set a prototype at any time.
76+
- Later, in the year 2015: `Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is optional for non-browser environments.
7777

7878
As of now we have all these ways at our disposal.
7979

@@ -82,7 +82,7 @@ Why was `__proto__` replaced by the functions `getPrototypeOf/setPrototypeOf`? T
8282
```warn header="Don't change `[[Prototype]]` on existing objects if speed matters"
8383
Technically, we can get/set `[[Prototype]]` at any time. But usually we only set it once at the object creation time, and then do not modify: `rabbit` inherits from `animal`, and that is not going to change.
8484

85-
And JavaScript engines are highly optimized to that. Changing a prototype "on-the-fly" with `Object.setPrototypeOf` or `obj.__proto__=` is a very slow operation, it breaks internal optimizations for object property access operations. So evade it unless you know what you're doing, or JavaScript speed totally doesn't matter for you.
85+
And JavaScript engines are highly optimized for this. Changing a prototype "on-the-fly" with `Object.setPrototypeOf` or `obj.__proto__=` is a very slow operation, it breaks internal optimizations for object property access operations. So avoid it unless you know what you're doing, or JavaScript speed totally doesn't matter for you.
8686
```
8787
8888
## "Very plain" objects [#very-plain]
@@ -108,17 +108,17 @@ That shouldn't surprise us. The `__proto__` property is special: it must be eith
108108

109109
But we didn't *intend* to implement such behavior, right? We want to store key/value pairs, and the key named `"__proto__"` was not properly saved. So that's a bug!
110110

111-
Here the consequences are not terrible. But in other cases, we may be assigning object values, then the prototype may indeed be changed. As the result, the execution will go wrong in totally unexpected ways.
111+
Here the consequences are not terrible. But in other cases we may be assigning object values, and then the prototype may indeed be changed. As the result, the execution will go wrong in totally unexpected ways.
112112

113-
What's worst -- usually developers do not think about such possibility at all. That makes such bugs hard to notice and even turn them into vulnerabilities, especially when JavaScript is used on server-side.
113+
What's worse -- usually developers do not think about such possibility at all. That makes such bugs hard to notice and even turn them into vulnerabilities, especially when JavaScript is used on server-side.
114114

115-
Unexpected things also may happen when assigning to `toString` -- that's a function by default, and other built-in methods.
115+
Unexpected things also may happen when assigning to `toString`, which is a function by default, and to other built-in methods.
116116

117-
How to evade the problem?
117+
How to avoid the problem?
118118

119119
First, we can just switch to using `Map`, then everything's fine.
120120

121-
But `Object` also can serve us well here, because language creators gave a thought to that problem long ago.
121+
But `Object` also can serve us well here, because language creators gave thought to that problem long ago.
122122

123123
The `__proto__` is not a property of an object, but an accessor property of `Object.prototype`:
124124

Diff for: 1-js/09-classes/01-class/article.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ new User().sayHi(); // Hello
231231

232232
## Getters/setters, other shorthands
233233

234-
Just like literal objects, classes may include getters/setters, generators, computed properties etc.
234+
Just like literal objects, classes may include getters/setters, computed properties etc.
235235

236236
Here's an example for `user.name` implemented using `get/set`:
237237

@@ -298,8 +298,6 @@ class User {
298298
new User().sayHi();
299299
```
300300

301-
For a generator method, similarly, prepend it with `*`.
302-
303301
## Class properties
304302

305303
```warn header="Old browsers may need a polyfill"

Diff for: 1-js/09-classes/02-class-inheritance/3-class-extend-object/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Even after the fix, there's still important difference in `"class Rabbit extends
2626
As we know, the "extends" syntax sets up two prototypes:
2727

2828
1. Between `"prototype"` of the constructor functions (for methods).
29-
2. Between the constructor functions itself (for static methods).
29+
2. Between the constructor functions themselves (for static methods).
3030

3131
In our case, for `class Rabbit extends Object` it means:
3232

Diff for: 1-js/09-classes/02-class-inheritance/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ The short answer is: constructors in inheriting classes must call `super(...)`,
259259

260260
...But why? What's going on here? Indeed, the requirement seems strange.
261261

262-
Of course, there's an explanation. Let's get into details, so you'd really understand what's going on.
262+
Of course, there's an explanation. Let's get into details, so you'll really understand what's going on.
263263

264264
In JavaScript, there's a distinction between a "constructor function of an inheriting class" and all others. In an inheriting class, the corresponding constructor function is labelled with a special internal property `[[ConstructorKind]]:"derived"`.
265265

Diff for: 1-js/09-classes/04-private-protected-properties-methods/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Unlike protected ones, private fields are enforced by the language itself. That'
248248
But if we inherit from `CoffeeMachine`, then we'll have no direct access to `#waterAmount`. We'll need to rely on `waterAmount` getter/setter:
249249

250250
```js
251-
class MegaCoffeeMachine extends CoffeeMachine() {
251+
class MegaCoffeeMachine extends CoffeeMachine {
252252
method() {
253253
*!*
254254
alert( this.#waterAmount ); // Error: can only access from CoffeeMachine

Diff for: 1-js/11-async/02-promise-basics/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ It's not exactly an alias of `then(f,f)` though. There are several important dif
267267
If a promise is pending, `.then/catch/finally` handlers wait for it. Otherwise, if a promise has already settled, they execute immediately:
268268
269269
```js run
270-
// an immediately resolved promise
270+
// the promise becomes resolved immediately upon creation
271271
let promise = new Promise(resolve => resolve("done!"));
272272
273273
promise.then(alert); // done! (shows up right now)

Diff for: 1-js/12-generators-iterators/2-async-iterators-generators/article.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let range = {
2121
[Symbol.iterator]() {
2222
*/!*
2323
// ...it returns the iterator object:
24-
// onward, for await..of works only with that object,
24+
// onward, for..of works only with that object,
2525
// asking it for next values using next()
2626
return {
2727
current: this.from,
@@ -345,20 +345,18 @@ When we expect the data to come asynchronously, with delays, their async counter
345345
346346
Syntax differences between async and regular iterators:
347347
348-
| | Iterators | Async iterators |
348+
| | Iterable | Async Iterable |
349349
|-------|-----------|-----------------|
350-
| Object method to provide iterator | `Symbol.iterator` | `Symbol.asyncIterator` |
351-
| `next()` return value is | any value | `Promise` |
350+
| Method to provide iterator | `Symbol.iterator` | `Symbol.asyncIterator` |
351+
| `next()` return value is | `{value:…, done: true/false}` | `Promise` that resolves to `{value:…, done: true/false}` |
352352
353353
Syntax differences between async and regular generators:
354354
355355
| | Generators | Async generators |
356356
|-------|-----------|-----------------|
357357
| Declaration | `function*` | `async function*` |
358-
| `generator.next()` returns | `{value:…, done: true/false}` | `Promise` that resolves to `{value:…, done: true/false}` |
358+
| `next()` return value is | `{value:…, done: true/false}` | `Promise` that resolves to `{value:…, done: true/false}` |
359359
360360
In web-development we often meet streams of data, when it flows chunk-by-chunk. For instance, downloading or uploading a big file.
361361
362-
We can use async generators to process such data, but it's also worth to mention that there's also another API called Streams, that provides special interfaces to work with such streams, to transform the data and to pass it from one stream to another (e.g. download from one place and immediately send elsewhere).
363-
364-
Streams API is not a part of JavaScript language standard.
362+
We can use async generators to process such data. It's also noteworthy that in some environments, such as browsers, there's also another API called Streams, that provides special interfaces to work with such streams, to transform the data and to pass it from one stream to another (e.g. download from one place and immediately send elsewhere).

Diff for: 1-js/13-modules/02-import-export/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ say.*!*hi*/!*('John'); // Hello, John!
151151
say.*!*bye*/!*('John'); // Bye, John!
152152
```
153153

154-
## export default
154+
## Export default
155155

156156
In practice, there are mainly two kinds of modules.
157157

@@ -305,7 +305,7 @@ import func from '/path/to/func.js';
305305
...
306306
```
307307

308-
Still, some teams consider it a serous drawback of default exports. So they prefer to always use named exports. Even if only a single thing is exported, it's still exported under a name, without `default`.
308+
Still, some teams consider it a serious drawback of default exports. So they prefer to always use named exports. Even if only a single thing is exported, it's still exported under a name, without `default`.
309309
310310
That also makes re-export (see below) a little bit easier.
311311

Diff for: 1-js/13-modules/03-modules-dynamic-imports/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ Dynamic imports work in regular scripts, they don't require `script type="module
9494
```smart
9595
Although `import()` looks like a function call, it's a special syntax that just happens to use parentheses (similar to `super()`).
9696
97-
So we can't copy `import` to a variable or use `.call/apply` with it. That's not a function.
97+
So we can't copy `import` to a variable or use `call/apply` with it. That's not a function.
9898
```

0 commit comments

Comments
 (0)