Skip to content

Commit fac4413

Browse files
authored
Merge pull request #1504 from hrodward/patch-24
Update article.md
2 parents 86891b9 + 6219338 commit fac4413

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ alert(f.__proto__.__proto__ == Object.prototype); // true, inherit from objects
9999

100100
The most intricate thing happens with strings, numbers and booleans.
101101

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

104104
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`.
105105

106106
```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.
108108
```
109109
110110
## Changing native prototypes [#native-prototype-change]
@@ -129,9 +129,9 @@ So, generally, modifying a native prototype is considered a bad idea.
129129

130130
**In modern programming, there is only one case where modifying native prototypes is approved. That's polyfilling.**
131131

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

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

136136
For instance:
137137

@@ -144,7 +144,7 @@ if (!String.prototype.repeat) { // if there's no such method
144144

145145
// actually, the code should be a little bit more complex than that
146146
// (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
148148
return new Array(n + 1).join(this);
149149
};
150150
}
@@ -179,18 +179,18 @@ obj.join = Array.prototype.join;
179179
alert( obj.join(',') ); // Hello,world!
180180
```
181181

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

184184
Another possibility is to inherit by setting `obj.__proto__` to `Array.prototype`, so all `Array` methods are automatically available in `obj`.
185185

186186
But that's impossible if `obj` already inherits from another object. Remember, we only can inherit from one object at a time.
187187

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

190190
## Summary
191191

192192
- 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

Comments
 (0)