Skip to content

Commit 4a94b22

Browse files
committed
Cosmetic.
1 parent 1546101 commit 4a94b22

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

doc/en/object/prototype.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
## The Prototype
22

3-
JavaScript does not feature a classical inheritance model; instead, it uses a
4-
*prototypal* one.
3+
JavaScript does not feature a classical inheritance model; instead, it uses a
4+
*prototypal* one.
55

6-
While this is often considered to be one of JavaScript's weaknesses, the
6+
While this is often considered to be one of JavaScript's weaknesses, the
77
prototypal inheritance model is in fact more powerful than the classic model.
88
It is, for example, fairly trivial to build a classic model on top of a
99
prototypal model, while the other way around is a far more difficult task.
1010

1111
JavaScript is the only widely used language that features prototypal
1212
inheritance, so it can take time to adjust to the differences between the two
13-
models.
13+
models.
1414

1515
The first major difference is that inheritance in JavaScript uses *prototype
1616
chains*.
1717

1818
> **Note:** Simply using `Bar.prototype = Foo.prototype` will result in both objects
19-
> sharing the **same** prototype. Therefore, changes to either object's prototype
20-
> will affect the prototype of the other as well, which in most cases is not the
19+
> sharing the **same** prototype. Therefore, changes to either object's prototype
20+
> will affect the prototype of the other as well, which in most cases is not the
2121
> desired effect.
2222
2323
function Foo() {
@@ -36,26 +36,26 @@ chains*.
3636
// Make sure to list Bar as the actual constructor
3737
Bar.prototype.constructor = Bar;
3838

39-
var test = new Bar() // create a new bar instance
39+
var test = new Bar(); // create a new bar instance
4040

4141
// The resulting prototype chain
4242
test [instance of Bar]
43-
Bar.prototype [instance of Foo]
43+
Bar.prototype [instance of Foo]
4444
{ foo: 'Hello World' }
4545
Foo.prototype
4646
{ method: ... }
4747
Object.prototype
4848
{ toString: ... /* etc. */ }
4949

5050
In the code above, the object `test` will inherit from both `Bar.prototype` and
51-
`Foo.prototype`; hence, it will have access to the function `method` that was
51+
`Foo.prototype`; hence, it will have access to the function `method` that was
5252
defined on `Foo`. It will also have access to the property `value` of the
5353
**one** `Foo` instance that is its prototype. It is important to note that `new
54-
Bar()` does **not** create a new `Foo` instance, but reuses the one assigned to
54+
Bar()` does **not** create a new `Foo` instance, but reuses the one assigned to
5555
its prototype; thus, all `Bar` instances will share the **same** `value` property.
5656

57-
> **Note:** Do **not** use `Bar.prototype = Foo`, since it will not point to
58-
> the prototype of `Foo` but rather to the function object `Foo`. So the
57+
> **Note:** Do **not** use `Bar.prototype = Foo`, since it will not point to
58+
> the prototype of `Foo` but rather to the function object `Foo`. So the
5959
> prototype chain will go over `Function.prototype` and not `Foo.prototype`;
6060
> therefore, `method` will not be on the prototype chain.
6161
@@ -71,7 +71,7 @@ hasn't found the specified property, it will return the value
7171
### The Prototype Property
7272

7373
While the prototype property is used by the language to build the prototype
74-
chains, it is still possible to assign **any** given value to it. However,
74+
chains, it is still possible to assign **any** given value to it. However,
7575
primitives will simply get ignored when assigned as a prototype.
7676

7777
function Foo() {}
@@ -85,22 +85,22 @@ creation of prototype chains.
8585
The lookup time for properties that are high up on the prototype chain can have
8686
a negative impact on performance, and this may be significant in code where
8787
performance is critical. Additionally, trying to access non-existent properties
88-
will always traverse the full prototype chain.
88+
will always traverse the full prototype chain.
8989

90-
Also, when [iterating](#object.forinloop) over the properties of an object
90+
Also, when [iterating](#object.forinloop) over the properties of an object
9191
**every** property that is on the prototype chain will be enumerated.
9292

9393
### Extension of Native Prototypes
9494

9595
One mis-feature that is often used is to extend `Object.prototype` or one of the
9696
other built in prototypes.
9797

98-
This technique is called [monkey patching][1] and breaks *encapsulation*. While
99-
used by popular frameworks such as [Prototype][2], there is still no good
98+
This technique is called [monkey patching][1] and breaks *encapsulation*. While
99+
used by popular frameworks such as [Prototype][2], there is still no good
100100
reason for cluttering built-in types with additional *non-standard* functionality.
101101

102-
The **only** good reason for extending a built-in prototype is to backport
103-
the features of newer JavaScript engines; for example,
102+
The **only** good reason for extending a built-in prototype is to backport
103+
the features of newer JavaScript engines; for example,
104104
[`Array.forEach`][3].
105105

106106
### In Conclusion

0 commit comments

Comments
 (0)