Skip to content

Commit c527cfd

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-70ca842b
2 parents 394bb6c + 70ca842 commit c527cfd

File tree

34 files changed

+119
-120
lines changed

34 files changed

+119
-120
lines changed

1-js/04-object-basics/04-object-methods/3-why-this/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 3
44

55
# Explain the value of "this"
66

7-
In the code below we intend to call `user.go()` method 4 times in a row.
7+
In the code below we intend to call `obj.go()` method 4 times in a row.
88

99
But calls `(1)` and `(2)` works differently from `(3)` and `(4)`. Why?
1010

1-js/05-data-types/05-array-methods/4-sort-back/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ importance: 4
22

33
---
44

5-
# Sort in the reverse order
5+
# Sort in decreasing order
66

77
```js
88
let arr = [5, 2, 1, -10, 8];
99

10-
// ... your code to sort it in the reverse order
10+
// ... your code to sort it in decreasing order
1111

1212
alert( arr ); // 8, 5, 2, 1, -10
1313
```

1-js/06-advanced-functions/08-settimeout-setinterval/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ For server-side JavaScript, that limitation does not exist, and there exist othe
288288

289289
- Methods `setTimeout(func, delay, ...args)` and `setInterval(func, delay, ...args)` allow us to run the `func` once/regularly after `delay` milliseconds.
290290
- To cancel the execution, we should call `clearTimeout/clearInterval` with the value returned by `setTimeout/setInterval`.
291-
- Nested `setTimeout` calls is a more flexible alternative to `setInterval`, allowing us to set the time *between* executions more precisely.
291+
- Nested `setTimeout` calls are a more flexible alternative to `setInterval`, allowing us to set the time *between* executions more precisely.
292292
- Zero delay scheduling with `setTimeout(func, 0)` (the same as `setTimeout(func)`) is used to schedule the call "as soon as possible, but after the current script is complete".
293293
- The browser limits the minimal delay for five or more nested call of `setTimeout` or for `setInterval` (after 5th call) to 4ms. That's for historical reasons.
294294

1-js/06-advanced-functions/10-bind/6-ask-partial/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The task is a little more complex variant of <info:task/question-use-bind>.
88

99
The `user` object was modified. Now instead of two functions `loginOk/loginFail`, it has a single function `user.login(true/false)`.
1010

11-
What to pass `askPassword` in the code below, so that it calls `user.login(true)` as `ok` and `user.login(false)` as `fail`?
11+
What should we pass `askPassword` in the code below, so that it calls `user.login(true)` as `ok` and `user.login(false)` as `fail`?
1212

1313
```js
1414
function askPassword(ok, fail) {

1-js/06-advanced-functions/10-bind/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Functions provide a built-in method [bind](mdn:js/Function/bind) that allows to
9898
The basic syntax is:
9999

100100
```js
101-
// more complex syntax will be little later
101+
// more complex syntax will come a little later
102102
let boundFunc = func.bind(context);
103103
```
104104

1-js/06-advanced-functions/12-arrow-functions/article.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ Here we had to create additional variables `args` and `ctx` so that the function
118118

119119
Arrow functions:
120120

121-
- Do not have `this`.
122-
- Do not have `arguments`.
123-
- Can't be called with `new`.
124-
- (They also don't have `super`, but we didn't study it. Will be in the chapter <info:class-inheritance>).
121+
- Do not have `this`
122+
- Do not have `arguments`
123+
- Can't be called with `new`
124+
- They also don't have `super`, but we didn't study it yet. We will on the chapter <info:class-inheritance>
125125

126-
That's because they are meant for short pieces of code that do not have their own "context", but rather works in the current one. And they really shine in that use case.
126+
That's because they are meant for short pieces of code that do not have their own "context", but rather work in the current one. And they really shine in that use case.

1-js/07-object-properties/01-property-descriptors/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
As we know, objects can store properties.
55

6-
Till now, a property was a simple "key-value" pair to us. But an object property is actually a more flexible and powerful thing.
6+
Until now, a property was a simple "key-value" pair to us. But an object property is actually a more flexible and powerful thing.
77

88
In this chapter we'll study additional configuration options, and in the next we'll see how to invisibly turn them into getter/setter functions.
99

@@ -134,7 +134,7 @@ let user = { };
134134
Object.defineProperty(user, "name", {
135135
*!*
136136
value: "John",
137-
// for new properties need to explicitly list what's true
137+
// for new properties we need to explicitly list what's true
138138
enumerable: true,
139139
configurable: true
140140
*/!*
@@ -148,7 +148,7 @@ user.name = "Pete"; // Error
148148

149149
Now let's add a custom `toString` to `user`.
150150

151-
Normally, a built-in `toString` for objects is non-enumerable, it does not show up in `for..in`. But if we add `toString` of our own, then by default it shows up in `for..in`, like this:
151+
Normally, a built-in `toString` for objects is non-enumerable, it does not show up in `for..in`. But if we add a `toString` of our own, then by default it shows up in `for..in`, like this:
152152

153153
```js run
154154
let user = {
@@ -162,7 +162,7 @@ let user = {
162162
for (let key in user) alert(key); // name, toString
163163
```
164164

165-
If we don't like it, then we can set `enumerable:false`. Then it won't appear in `for..in` loop, just like the built-in one:
165+
If we don't like it, then we can set `enumerable:false`. Then it won't appear in a `for..in` loop, just like the built-in one:
166166

167167
```js run
168168
let user = {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
There are two kinds of properties.
55

6-
The first kind is *data properties*. We already know how to work with them. All properties that we've been using till now were data properties.
6+
The first kind is *data properties*. We already know how to work with them. All properties that we've been using until now were data properties.
77

88
The second type of properties is something new. It's *accessor properties*. They are essentially functions that work on getting and setting a value, but look like regular properties to an external code.
99

@@ -189,9 +189,9 @@ Technically, external code is able to access the name directly by using `user._n
189189

190190
## Using for compatibility
191191

192-
One of the great uses of accessors -- they allow to take control over a "regular" data property at any moment by replacing it with getter and setter and tweak its behavior.
192+
One of the great uses of accessors is that they allow to take control over a "regular" data property at any moment by replacing it with a getter and a setter and tweak its behavior.
193193

194-
Imagine, we started implementing user objects using data properties `name` and `age`:
194+
Imagine we started implementing user objects using data properties `name` and `age`:
195195

196196
```js
197197
function User(name, age) {

1-js/08-prototypes/01-prototype-inheritance/2-search-algorithm/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 5
66

77
The task has two parts.
88

9-
We have objects:
9+
Given the following objects:
1010

1111
```js
1212
let head = {

1-js/08-prototypes/01-prototype-inheritance/3-proto-and-this/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ importance: 5
22

33
---
44

5-
# Where it writes?
5+
# Where does it write?
66

77
We have `rabbit` inheriting from `animal`.
88

1-js/08-prototypes/01-prototype-inheritance/4-hamster-proto/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ importance: 5
22

33
---
44

5-
# Why two hamsters are full?
5+
# Why are both hamsters full?
66

77
We have two hamsters: `speedy` and `lazy` inheriting from the general `hamster` object.
88

9-
When we feed one of them, the other one is also full. Why? How to fix it?
9+
When we feed one of them, the other one is also full. Why? How can we fix it?
1010

1111
```js run
1212
let hamster = {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ rabbit.__proto__ = animal;
3434
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
3535
Please note that `__proto__` is *not the same* as `[[Prototype]]`. That's a getter/setter for it.
3636

37-
It exists for historical reasons, in modern language it is replaced with functions `Object.getPrototypeOf/Object.setPrototypeOf` that also get/set the prototype. We'll study the reasons for that and these functions later.
37+
It exists for historical reasons. In modern language it is replaced with functions `Object.getPrototypeOf/Object.setPrototypeOf` that also get/set the prototype. We'll study the reasons for that and these functions later.
3838

3939
By the specification, `__proto__` must only be supported by browsers, but in fact all environments including server-side support it. For now, as `__proto__` notation is a little bit more intuitively obvious, we'll use it in the examples.
4040
```
@@ -203,7 +203,7 @@ Here in the line `(*)` the property `admin.fullName` has a getter in the prototy
203203

204204
## The value of "this"
205205

206-
An interesting question may arise in the example above: what's the value of `this` inside `set fullName(value)`? Where the properties `this.name` and `this.surname` are written: into `user` or `admin`?
206+
An interesting question may arise in the example above: what's the value of `this` inside `set fullName(value)`? Where are the properties `this.name` and `this.surname` written: into `user` or `admin`?
207207

208208
The answer is simple: `this` is not affected by prototypes at all.
209209

@@ -246,13 +246,13 @@ The resulting picture:
246246

247247
![](proto-animal-rabbit-walk-3.svg)
248248

249-
If we had other objects like `bird`, `snake` etc inheriting from `animal`, they would also gain access to methods of `animal`. But `this` in each method call would be the corresponding object, evaluated at the call-time (before dot), not `animal`. So when we write data into `this`, it is stored into these objects.
249+
If we had other objects, like `bird`, `snake`, etc., inheriting from `animal`, they would also gain access to methods of `animal`. But `this` in each method call would be the corresponding object, evaluated at the call-time (before dot), not `animal`. So when we write data into `this`, it is stored into these objects.
250250

251251
As a result, methods are shared, but the object state is not.
252252

253253
## for..in loop
254254

255-
The `for..in` loops over inherited properties too.
255+
The `for..in` loop iterates over inherited properties too.
256256

257257
For instance:
258258

@@ -267,7 +267,7 @@ let rabbit = {
267267
};
268268

269269
*!*
270-
// Object.keys only return own keys
270+
// Object.keys only returns own keys
271271
alert(Object.keys(rabbit)); // jumps
272272
*/!*
273273

1-js/08-prototypes/02-function-prototype/1-changing-prototype/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ alert( rabbit.eats ); // true
2020
```
2121

2222

23-
1. We added one more string (emphasized), what `alert` shows now?
23+
1. We added one more string (emphasized). What will `alert` show now?
2424

2525
```js
2626
function Rabbit() {}
@@ -54,7 +54,7 @@ alert( rabbit.eats ); // true
5454
alert( rabbit.eats ); // ?
5555
```
5656

57-
3. Like this (replaced one line)?
57+
3. And like this (replaced one line)?
5858

5959
```js
6060
function Rabbit() {}

1-js/08-prototypes/02-function-prototype/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Remember, new objects can be created with a constructor function, like `new F()`.
44

5-
If `F.prototype` is an object, then `new` operator uses it to set `[[Prototype]]` for the new object.
5+
If `F.prototype` is an object, then the `new` operator uses it to set `[[Prototype]]` for the new object.
66

77
```smart
88
JavaScript had prototypal inheritance from the beginning. It was one of the core features of the language.
@@ -158,9 +158,9 @@ Rabbit.prototype = {
158158

159159
In this chapter we briefly described the way of setting a `[[Prototype]]` for objects created via a constructor function. Later we'll see more advanced programming patterns that rely on it.
160160

161-
Everything is quite simple, just few notes to make things clear:
161+
Everything is quite simple, just a few notes to make things clear:
162162

163-
- The `F.prototype` property (don't mess with `[[Prototype]]`) sets `[[Prototype]]` of new objects when `new F()` is called.
163+
- The `F.prototype` property (don't mistake it for `[[Prototype]]`) sets `[[Prototype]]` of new objects when `new F()` is called.
164164
- The value of `F.prototype` should be either an object or `null`: other values won't work.
165165
- The `"prototype"` property only has such a special effect when set on a constructor function, and invoked with `new`.
166166

1-js/08-prototypes/03-native-prototypes/article.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ alert(f.__proto__.__proto__ == Object.prototype); // true, inherit from objects
9999

100100
The most intricate thing happens with strings, numbers and booleans.
101101

102-
As we remember, they are not objects. But if we try to access their properties, then temporary wrapper objects are created using built-in constructors `String`, `Number`, `Boolean`, they provide the methods and disappear.
102+
As we remember, they are not objects. But if we try to access their properties, temporary wrapper objects are created using built-in constructors `String`, `Number` and `Boolean`. They provide the methods and disappear.
103103

104104
These objects are created invisibly to us and most engines optimize them out, but the specification describes it exactly this way. Methods of these objects also reside in prototypes, available as `String.prototype`, `Number.prototype` and `Boolean.prototype`.
105105

106106
```warn header="Values `null` and `undefined` have no object wrappers"
107-
Special values `null` and `undefined` stand apart. They have no object wrappers, so methods and properties are not available for them. And there are no corresponding prototypes too.
107+
Special values `null` and `undefined` stand apart. They have no object wrappers, so methods and properties are not available for them. And there are no corresponding prototypes either.
108108
```
109109
110110
## Changing native prototypes [#native-prototype-change]
@@ -129,9 +129,9 @@ 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 is not yet supported by current JavaScript engine.
132+
Polyfilling is a term for making a substitute for a method that exists in the JavaScript specification, but is not yet supported by a particular JavaScript engine.
133133

134-
Then we may implement it manually and populate the built-in prototype with it.
134+
We may then implement it manually and populate the built-in prototype with it.
135135

136136
For instance:
137137

@@ -144,7 +144,7 @@ if (!String.prototype.repeat) { // if there's no such method
144144

145145
// actually, the code should be a little bit more complex than that
146146
// (the full algorithm is in the specification)
147-
// but even an imperfect polyfill is often considered good enough for use
147+
// but even an imperfect polyfill is often considered good enough
148148
return new Array(n + 1).join(this);
149149
};
150150
}
@@ -179,18 +179,18 @@ obj.join = Array.prototype.join;
179179
alert( obj.join(',') ); // Hello,world!
180180
```
181181

182-
It works, because the internal algorithm of the built-in `join` method only cares about the correct indexes and the `length` property, it doesn't check that the object is indeed the array. And many built-in methods are like that.
182+
It works because the internal algorithm of the built-in `join` method only cares about the correct indexes and the `length` property. It doesn't check if the object is indeed an array. Many built-in methods are like that.
183183

184184
Another possibility is to inherit by setting `obj.__proto__` to `Array.prototype`, so all `Array` methods are automatically available in `obj`.
185185

186186
But that's impossible if `obj` already inherits from another object. Remember, we only can inherit from one object at a time.
187187

188-
Borrowing methods is flexible, it allows to mix functionality from different objects if needed.
188+
Borrowing methods is flexible, it allows to mix functionalities from different objects if needed.
189189

190190
## Summary
191191

192192
- All built-in objects follow the same pattern:
193-
- The methods are stored in the prototype (`Array.prototype`, `Object.prototype`, `Date.prototype` etc).
194-
- The object itself stores only the data (array items, object properties, the date).
195-
- Primitives also store methods in prototypes of wrapper objects: `Number.prototype`, `String.prototype`, `Boolean.prototype`. Only `undefined` and `null` do not have wrapper objects.
196-
- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. Probably the only allowable case is when we add-in a new standard, but not yet supported by the engine JavaScript method.
193+
- The methods are stored in the prototype (`Array.prototype`, `Object.prototype`, `Date.prototype`, etc.)
194+
- The object itself stores only the data (array items, object properties, the date)
195+
- Primitives also store methods in prototypes of wrapper objects: `Number.prototype`, `String.prototype` and `Boolean.prototype`. Only `undefined` and `null` do not have wrapper objects
196+
- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. The only allowable case is probably when we add-in a new standard, but it's not yet supported by the JavaScript engine

0 commit comments

Comments
 (0)