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/06-advanced-functions/08-settimeout-setinterval/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -288,7 +288,7 @@ For server-side JavaScript, that limitation does not exist, and there exist othe
288
288
289
289
- Methods `setTimeout(func, delay, ...args)` and `setInterval(func, delay, ...args)` allow us to run the `func` once/regularly after `delay` milliseconds.
290
290
- 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.
292
292
- 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".
293
293
- 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.
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/12-arrow-functions/article.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -118,9 +118,9 @@ Here we had to create additional variables `args` and `ctx` so that the function
118
118
119
119
Arrow functions:
120
120
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>
125
125
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.
Copy file name to clipboardExpand all lines: 1-js/07-object-properties/01-property-descriptors/article.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
As we know, objects can store properties.
5
5
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.
7
7
8
8
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.
9
9
@@ -134,7 +134,7 @@ let user = { };
134
134
Object.defineProperty(user, "name", {
135
135
*!*
136
136
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
138
138
enumerable:true,
139
139
configurable:true
140
140
*/!*
@@ -148,7 +148,7 @@ user.name = "Pete"; // Error
148
148
149
149
Now let's add a custom `toString` to `user`.
150
150
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:
152
152
153
153
```js run
154
154
let user = {
@@ -162,7 +162,7 @@ let user = {
162
162
for (let key in user) alert(key); // name, toString
163
163
```
164
164
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:
Copy file name to clipboardExpand all lines: 1-js/07-object-properties/02-property-accessors/article.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
There are two kinds of properties.
5
5
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.
7
7
8
8
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.
9
9
@@ -189,9 +189,9 @@ Technically, external code is able to access the name directly by using `user._n
189
189
190
190
## Using for compatibility
191
191
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.
193
193
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`:
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/01-prototype-inheritance/article.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ rabbit.__proto__ = animal;
34
34
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
35
35
Please note that `__proto__` is *not the same* as `[[Prototype]]`. That's a getter/setter for it.
36
36
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.
38
38
39
39
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.
40
40
```
@@ -203,7 +203,7 @@ Here in the line `(*)` the property `admin.fullName` has a getter in the prototy
203
203
204
204
## The value of "this"
205
205
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`?
207
207
208
208
The answer is simple: `this` is not affected by prototypes at all.
209
209
@@ -246,13 +246,13 @@ The resulting picture:
246
246
247
247

248
248
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.
250
250
251
251
As a result, methods are shared, but the object state is not.
252
252
253
253
## for..in loop
254
254
255
-
The `for..in`loops over inherited properties too.
255
+
The `for..in`loop iterates over inherited properties too.
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/02-function-prototype/article.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Remember, new objects can be created with a constructor function, like `new F()`.
4
4
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.
6
6
7
7
```smart
8
8
JavaScript had prototypal inheritance from the beginning. It was one of the core features of the language.
@@ -158,9 +158,9 @@ Rabbit.prototype = {
158
158
159
159
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.
160
160
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:
162
162
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.
164
164
- The value of `F.prototype` should be either an object or `null`: other values won'twork.
165
165
-The`"prototype"`propertyonlyhassuchaspecialeffectwhensetonaconstructor function, and invoked with `new`.
The most intricate thing happens with strings, numbers and booleans.
101
101
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.
103
103
104
104
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`.
105
105
106
106
```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.
@@ -129,9 +129,9 @@ So, generally, modifying a native prototype is considered a bad idea.
129
129
130
130
**In modern programming, there is only one case where modifying native prototypes is approved. That's polyfilling.**
131
131
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.
133
133
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.
135
135
136
136
For instance:
137
137
@@ -144,7 +144,7 @@ if (!String.prototype.repeat) { // if there's no such method
144
144
145
145
// actually, the code should be a little bit more complex than that
146
146
// (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
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.
183
183
184
184
Another possibility is to inherit by setting `obj.__proto__` to `Array.prototype`, so all `Array` methods are automatically available in `obj`.
185
185
186
186
But that's impossible if `obj` already inherits from another object. Remember, we only can inherit from one object at a time.
187
187
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.
189
189
190
190
## Summary
191
191
192
192
- 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