Skip to content

Commit 9302563

Browse files
authored
Merge pull request #255 from odsantos/update-native-prototypes
Update Native Prototypes article
2 parents f62ce7c + e09bdc9 commit 9302563

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `"prototype"` property is widely used by the core of JavaScript itself. All built-in constructor functions use it.
44

5-
We'll see how it is for plain objects first, and then for more complex ones.
5+
First we'll look at the details, and then how to use it for adding new capabilities to built-in objects.
66

77
## Object.prototype
88

@@ -38,7 +38,7 @@ alert(obj.toString === obj.__proto__.toString); //true
3838
alert(obj.toString === Object.prototype.toString); //true
3939
```
4040

41-
Please note that there is no additional `[[Prototype]]` in the chain above `Object.prototype`:
41+
Please note that there is no more `[[Prototype]]` in the chain above `Object.prototype`:
4242

4343
```js run
4444
alert(Object.prototype.__proto__); // null
@@ -48,9 +48,9 @@ alert(Object.prototype.__proto__); // null
4848

4949
Other built-in objects such as `Array`, `Date`, `Function` and others also keep methods in prototypes.
5050

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.
5252

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".
5454

5555
Here's the overall picture (for 3 built-ins to fit):
5656

@@ -124,7 +124,7 @@ String.prototype.show = function() {
124124
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.
125125

126126
```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.
128128
129129
So, generally, modifying a native prototype is considered a bad idea.
130130
```
@@ -163,7 +163,7 @@ That's when we take a method from one object and copy it into another.
163163

164164
Some methods of native prototypes are often borrowed.
165165

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.
167167

168168
E.g.
169169

0 commit comments

Comments
 (0)