@@ -4,16 +4,16 @@ JavaScript does not feature a classical inheritance model; instead, it uses a
44* prototypal* one.
55
66While this is often considered to be one of JavaScript's weaknesses, the
7- prototypal inheritance model is in fact more powerful than the classic model.
8- It is, for example, fairly trivial to build a classic model on top of it, while the
9- other way around is a far more difficult task.
7+ prototypal inheritance model is in fact more powerful than the classic model.
8+ It is, for example, fairly trivial to build a classic model on top of a
9+ prototypal model, while the other way around is a far more difficult task.
1010
11- Due to the fact that JavaScript is basically the only widely used language that
12- features prototypal inheritance, it takes some time to adjust to the
13- differences between the two models.
11+ JavaScript is the only widely used language that features prototypal
12+ inheritance, so it can take time to adjust to the differences between the two
13+ models.
1414
15- The first major difference is that inheritance in JavaScript is done by using so
16- called * prototype chains* .
15+ The first major difference is that inheritance in JavaScript uses * prototype
16+ chains* .
1717
1818> ** Note:** Simply using ` Bar.prototype = Foo.prototype ` will result in both objects
1919> sharing the ** same** prototype. Therefore, changes to either object's prototype
@@ -47,7 +47,7 @@ called *prototype chains*.
4747 Object.prototype
4848 { toString: ... /* etc. */ }
4949
50- In the above, the object ` test ` will inherit from both ` Bar.prototype ` and
50+ In the code above, the object ` test ` will inherit from both ` Bar.prototype ` and
5151` Foo.prototype ` ; hence, it will have access to the function ` method ` that was
5252defined 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
@@ -64,7 +64,7 @@ its prototype; thus, all `Bar` instances will share the **same** `value` propert
6464When accessing the properties of an object, JavaScript will traverse the
6565prototype chain ** upwards** until it finds a property with the requested name.
6666
67- When it reaches the top of the chain - namely ` Object.prototype ` - and still
67+ If it reaches the top of the chain - namely ` Object.prototype ` - and still
6868hasn't found the specified property, it will return the value
6969[ undefined] ( #core.undefined ) instead.
7070
@@ -82,20 +82,21 @@ creation of prototype chains.
8282
8383### Performance
8484
85- The lookup time for properties that are high up on the prototype chain can have a
86- negative impact on performance critical sections of code. Additionally, trying to
87- access non-existent properties will always traverse the full prototype chain.
85+ The lookup time for properties that are high up on the prototype chain can have
86+ a negative impact on performance, and this may be significant in code where
87+ performance is critical. Additionally, trying to access non-existent properties
88+ will always traverse the full prototype chain.
8889
8990Also, when [ iterating] ( #object.forinloop ) over the properties of an object
90- ** every** property that is on the prototype chain will get enumerated.
91+ ** every** property that is on the prototype chain will be enumerated.
9192
9293### Extension of Native Prototypes
9394
9495One mis-feature that is often used is to extend ` Object.prototype ` or one of the
9596other built in prototypes.
9697
9798This technique is called [ monkey patching] [ 1 ] and breaks * encapsulation* . While
98- used by widely spread frameworks such as [ Prototype] [ 2 ] , there is still no good
99+ used by popular frameworks such as [ Prototype] [ 2 ] , there is still no good
99100reason for cluttering built-in types with additional * non-standard* functionality.
100101
101102The ** only** good reason for extending a built-in prototype is to backport
@@ -104,11 +105,12 @@ the features of newer JavaScript engines; for example,
104105
105106### In Conclusion
106107
107- It is a ** must** to understand the prototypal inheritance model completely
108- before writing complex code which makes use of it. Also, watch the length of
109- the prototype chains and break them up if necessary to avoid possible
110- performance issues. Further, the native prototypes should ** never** be extended
111- unless it is for the sake of compatibility with newer JavaScript features.
108+ It is ** essential** to understand the prototypal inheritance model before
109+ writing complex code that makes use of it. Also, be aware of the length of the
110+ prototype chains in your code and break them up if necessary to avoid possible
111+ performance problems. Further, the native prototypes should ** never** be
112+ extended unless it is for the sake of compatibility with newer JavaScript
113+ features.
112114
113115[ 1 ] : http://en.wikipedia.org/wiki/Monkey_patch
114116[ 2 ] : http://prototypejs.org/
0 commit comments