Skip to content

Commit adf7fb4

Browse files
authored
Merge branch 'master' into patch-43
2 parents 1d2fe95 + 851acfc commit adf7fb4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 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 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

0 commit comments

Comments
 (0)