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
Other built-in objects such as `Array`, `Date`, `Function` and others also keep methods in prototypes.
50
50
51
-
For instance, when we create an array `[1, 2, 3]`, the default `new Array()` constructor is used internally. So the array data is written into the new object, and`Array.prototype` becomes its prototype and provides methods. That's very memory-efficient.
51
+
For instance, when we create an array `[1, 2, 3]`, the default `new Array()` constructor is used internally. So `Array.prototype` becomes its prototype and provides methods. That's very memory-efficient.
52
52
53
-
By specification, all of the built-in prototypes have `Object.prototype` on the top. Sometimes people say that "everything inherits from objects".
53
+
By specification, all of the built-in prototypes have `Object.prototype` on the top. That's why some people say that "everything inherits from objects".
54
54
55
55
Here's the overall picture (for 3 built-ins to fit):
During the process of development, we may have ideas for new built-in methods we'd like to have, and we may be tempted to add them to native prototypes. But that is generally a bad idea.
125
125
126
126
```warn
127
-
Prototypes are global, so it's easy to get a conflict. If two libraries add a method `String.prototype.show`, then one of them will be overwriting the other.
127
+
Prototypes are global, so it's easy to get a conflict. If two libraries add a method `String.prototype.show`, then one of them will be overwriting the method of the other.
128
128
129
129
So, generally, modifying a native prototype is considered a bad idea.
130
130
```
@@ -163,7 +163,7 @@ That's when we take a method from one object and copy it into another.
163
163
164
164
Some methods of native prototypes are often borrowed.
165
165
166
-
For instance, if we're making an array-like object, we may want to copy some array methods to it.
166
+
For instance, if we're making an array-like object, we may want to copy some `Array` methods to it.
0 commit comments