Skip to content

Commit 3f753a1

Browse files
authored
Merge pull request #917 from dragonwocky/patch-2
Smooth over some wording
2 parents d50fff0 + 81a37be commit 3f753a1

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ alert( obj ); // "[object Object]" ?
1515

1616
Where's the code that generates the string `"[object Object]"`? That's a built-in `toString` method, but where is it? The `obj` is empty!
1717

18-
...But the short notation `obj = {}` is the same as `obj = new Object()`, where `Object` -- is a built-in object constructor function. And that function has `Object.prototype` that references a huge object with `toString` and other functions.
18+
...But the short notation `obj = {}` is the same as `obj = new Object()`, where `Object` is a built-in object constructor function, with its own `prototype` referencing a huge object with `toString` and other methods.
1919

20-
Like this (all that is built-in):
20+
Here's what's going on:
2121

2222
![](object-prototype.png)
2323

24-
When `new Object()` is called (or a literal object `{...}` is created), the `[[Prototype]]` of it is set to `Object.prototype` by the rule that we've discussed in the previous chapter:
24+
When `new Object()` is called (or a literal object `{...}` is created), the `[[Prototype]]` of it is set to `Object.prototype` according to the rule that we discussed in the previous chapter:
2525

2626
![](object-prototype-1.png)
2727

28-
Afterwards when `obj.toString()` is called -- the method is taken from `Object.prototype`.
28+
So then when `obj.toString()` is called the method is taken from `Object.prototype`.
2929

3030
We can check it like this:
3131

@@ -48,7 +48,7 @@ Other built-in objects such as `Array`, `Date`, `Function` and others also keep
4848

4949
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.
5050

51-
By specification, all built-in prototypes have `Object.prototype` on the top. Sometimes people say that "everything inherits from objects".
51+
By specification, all of the built-in prototypes have `Object.prototype` on the top. Sometimes people say that "everything inherits from objects".
5252

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

@@ -82,11 +82,11 @@ As we've seen before, `Object.prototype` has `toString` as well, but `Array.prot
8282
![](native-prototypes-array-tostring.png)
8383

8484

85-
In-browser tools like Chrome developer console also show inheritance (may need to use `console.dir` for built-in objects):
85+
In-browser tools like Chrome developer console also show inheritance (`console.dir` may need to be used for built-in objects):
8686

8787
![](console_dir_array.png)
8888

89-
Other built-in objects also work the same way. Even functions. They are objects of a built-in `Function` constructor, and their methods: `call/apply` and others are taken from `Function.prototype`. Functions have their own `toString` too.
89+
Other built-in objects also work the same way. Even functions -- they are objects of a built-in `Function` constructor, and their methods (`call`/`apply` and others) are taken from `Function.prototype`. Functions have their own `toString` too.
9090

9191
```js run
9292
function f() {}
@@ -119,17 +119,17 @@ String.prototype.show = function() {
119119
"BOOM!".show(); // BOOM!
120120
```
121121

122-
During the process of development we may have ideas which new built-in methods we'd like to have. And there may be a slight temptation to add them to native prototypes. But that is generally a bad idea.
122+
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.
123123

124124
```warn
125-
Prototypes are global, so it's easy to get a conflict. If two libraries add a method `String.prototype.show`, then one of them overwrites the other one.
125+
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.
126126
127-
So, generally modifying a native prototypeis considered a bad idea.
127+
So, generally, modifying a native prototype is considered a bad idea.
128128
```
129129

130-
**In modern programming, there is only one case when modifying native prototypes is approved. That's polyfilling.**
130+
**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 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 not yet supported by current JavaScript engine.
133133

134134
Then we may implement it manually and populate the built-in prototype with it.
135135

@@ -181,7 +181,7 @@ alert( obj.join(',') ); // Hello,world!
181181

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

184-
Another possibility is to inherit by setting `obj.__proto__` to `Array.prototype`, then all `Array` methods are automatically available in `obj`.
184+
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

@@ -192,5 +192,5 @@ Borrowing methods is flexible, it allows to mix functionality from different obj
192192
- All built-in objects follow the same pattern:
193193
- The methods are stored in the prototype (`Array.prototype`, `Object.prototype`, `Date.prototype` etc).
194194
- 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`. There are no wrapper objects only for `undefined` and `null`.
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.
196196
- Built-in prototypes can be modified or populated with new methods. But it's not recommended to change them. Probably the only allowable cause is when we add-in a new standard, but not yet supported by the engine JavaScript method.

1-js/09-classes/05-private-protected-properties-methods/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ coffeeMachine.#waterLimit = 1000; // Error
230230
coffeeMachine.waterAmount = 100; // Works
231231
```
232232

233-
On the language level, `#` is a special sign that the field is private. We can't access it from outside or from inhereting classes.
233+
On the language level, `#` is a special sign that the field is private. We can't access it from outside or from inheriting classes.
234234

235235
Private fields do not conflict with public ones. We can have both private `#waterAmount` and public `waterAmount` fields at the same time.
236236

@@ -257,7 +257,7 @@ machine.waterAmount = 100;
257257
alert(machine.#waterAmount); // Error
258258
```
259259

260-
Unlike protected ones, private fields are enforced by the language itselfs. That's a good thing.
260+
Unlike protected ones, private fields are enforced by the language itself. That's a good thing.
261261

262262
But if we inherit from `CoffeeMachine`, then we'll have no direct access to `#waterAmount`. We'll need to rely on `waterAmount` getter/setter:
263263

1-js/09-classes/06-extend-natives/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Extending build-in classes
2+
# Extending built-in classes
33

44
Built-in classes like Array, Map and others are extendable also.
55

@@ -29,7 +29,7 @@ arr.constructor === PowerArray
2929
```
3030

3131
So when `arr.filter()` is called, it internally creates the new array of results exactly as `new PowerArray`.
32-
That's actually very cool, because we can keep using `PowerArray` methods further o the result.
32+
That's actually very cool, because we can keep using `PowerArray` methods further on the result.
3333

3434
Even more, we can customize that behavior.
3535

@@ -73,7 +73,7 @@ And we've already been talking about native classes extending each other: `Array
7373

7474
But statics are an exception. Built-in classes don't inherit static properties from each other.
7575

76-
In other words, the prototype of build-in constructor `Array` does not point to `Object`. This way `Array` and `Date` do not have `Array.keys` or `Date.keys`. And that feels natural.
76+
In other words, the prototype of built-in constructor `Array` does not point to `Object`. This way `Array` and `Date` do not have `Array.keys` or `Date.keys`. And that feels natural.
7777

7878
Here's the picture structure for `Date` and `Object`:
7979

0 commit comments

Comments
 (0)