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/02-first-steps/04-variables/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
@@ -290,7 +290,7 @@ In other words, capital-named constants are only used as aliases for "hard-coded
290
290
291
291
Talking about variables, there's one more extremely important thing.
292
292
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.
294
294
295
295
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.
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/03-native-prototypes/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
@@ -129,7 +129,7 @@ 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 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.
133
133
134
134
Then we may implement it manually and populate the built-in prototype with it.
Copy file name to clipboardExpand all lines: 1-js/08-prototypes/04-prototype-methods/article.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,8 +72,8 @@ Why so?
72
72
That's for historical reasons.
73
73
74
74
- 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.
77
77
78
78
As of now we have all these ways at our disposal.
79
79
@@ -82,7 +82,7 @@ Why was `__proto__` replaced by the functions `getPrototypeOf/setPrototypeOf`? T
82
82
```warn header="Don't change `[[Prototype]]` on existing objects if speed matters"
83
83
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.
84
84
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.
86
86
```
87
87
88
88
## "Very plain" objects [#very-plain]
@@ -108,17 +108,17 @@ That shouldn't surprise us. The `__proto__` property is special: it must be eith
108
108
109
109
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!
110
110
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.
112
112
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.
114
114
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.
116
116
117
-
How to evade the problem?
117
+
How to avoid the problem?
118
118
119
119
First, we can just switch to using `Map`, then everything's fine.
120
120
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.
122
122
123
123
The `__proto__` is not a property of an object, but an accessor property of `Object.prototype`:
Copy file name to clipboardExpand all lines: 1-js/09-classes/02-class-inheritance/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
@@ -259,7 +259,7 @@ The short answer is: constructors in inheriting classes must call `super(...)`,
259
259
260
260
...But why? What's going on here? Indeed, the requirement seems strange.
261
261
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.
263
263
264
264
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"`.
0 commit comments