Skip to content

Commit 3dc251c

Browse files
Clean up language in the object section.
1 parent 5f55365 commit 3dc251c

File tree

4 files changed

+48
-46
lines changed

4 files changed

+48
-46
lines changed

doc/en/object/forinloop.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## The `for in` Loop
22

3-
Just like the `in` operator, the `for in` loop also traverses the prototype
3+
Just like the `in` operator, the `for in` loop traverses the prototype
44
chain when iterating over the properties of an object.
55

66
> **Note:** The `for in` loop will **not** iterate over any properties that
@@ -17,10 +17,10 @@ chain when iterating over the properties of an object.
1717

1818
Since it is not possible to change the behavior of the `for in` loop itself, it
1919
is necessary to filter out the unwanted properties inside the loop body;
20-
this is done by using the [`hasOwnProperty`](#object.hasownproperty) method of
20+
this is done using the [`hasOwnProperty`](#object.hasownproperty) method of
2121
`Object.prototype`.
2222

23-
> **Note:** Since the `for in` always traverses the complete prototype chain, it
23+
> **Note:** Since `for in` always traverses the complete prototype chain, it
2424
> will get slower with each additional layer of inheritance added to an object.
2525
2626
### Using `hasOwnProperty` for Filtering
@@ -37,15 +37,15 @@ will **only** print out `moo`. When `hasOwnProperty` is left out, the code is
3737
prone to errors in cases where the native prototypes - e.g. `Object.prototype` -
3838
have been extended.
3939

40-
One widely used framework which does this is [Prototype][1]. When this
41-
framework is included, `for in` loops that do not use `hasOwnProperty` are
42-
guaranteed to break.
40+
One widely used framework that extends `Object.prototype` is [Prototype][1].
41+
When this framework is included, `for in` loops that do not use
42+
`hasOwnProperty` are guaranteed to break.
4343

4444
### In Conclusion
4545

46-
It is recommended to **always** use `hasOwnProperty`. Never should any
47-
assumptions be made about the environment the code is running in, or whether the
48-
native prototypes have been extended or not.
46+
It is recommended to **always** use `hasOwnProperty`. Assumptions should never
47+
be made about the environment the code is running in, or whether the native
48+
prototypes have been extended or not.
4949

5050
[1]: http://www.prototypejs.org/
5151

doc/en/object/general.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ notation* on a number as a floating point literal.
1616

1717
2.toString(); // raises SyntaxError
1818

19-
There are a couple of workarounds which can be used in order make number
20-
literals act as objects too.
19+
There are a couple of workarounds that can be used to make number literals act
20+
as objects too.
2121

2222
2..toString(); // the second point is correctly recognized
2323
2 .toString(); // note the space left to the dot
2424
(2).toString(); // 2 is evaluated first
2525

2626
### Objects as a Data Type
2727

28-
Objects in JavaScript can also be used as a [*Hashmap*][1]; they mainly consist
28+
Objects in JavaScript can also be used as [*Hashmaps*][1]; they mainly consist
2929
of named properties mapping to values.
3030

3131
Using an object literal - `{}` notation - it is possible to create a
3232
plain object. This new object [inherits](#object.prototype) from `Object.prototype` and
33-
has no [own properties](#object.hasownproperty) defined on it.
33+
does not have [own properties](#object.hasownproperty) defined.
3434

3535
var foo = {}; // a new empty object
3636

37-
// a new object with a property called 'test' with value 12
37+
// a new object with a 'test' property with value 12
3838
var bar = {test: 12};
3939

4040
### Accessing Properties
@@ -52,13 +52,13 @@ notation or the square bracket notation.
5252
foo.1234; // SyntaxError
5353
foo['1234']; // works
5454

55-
Both notations are identical in their workings, with the only difference being that
56-
the square bracket notation allows for dynamic setting of properties, as well as
55+
The notations work almost identically, with the only difference being that the
56+
square bracket notation allows for dynamic setting of properties and
5757
the use of property names that would otherwise lead to a syntax error.
5858

5959
### Deleting Properties
6060

61-
The only way to actually remove a property from an object is to use the `delete`
61+
The only way to remove a property from an object is to use the `delete`
6262
operator; setting the property to `undefined` or `null` only removes the
6363
*value* associated with the property, but not the *key*.
6464

doc/en/object/hasownproperty.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## `hasOwnProperty`
22

3-
In order to check whether a object has a property defined on *itself* and **not**
4-
somewhere on its [prototype chain](#object.prototype), it is necessary to use the
3+
To check whether an object has a property defined on *itself* and not somewhere
4+
on its [prototype chain](#object.prototype), it is necessary to use the
55
`hasOwnProperty` method which all objects inherit from `Object.prototype`.
66

77
> **Note:** It is **not** enough to check whether a property is `undefined`. The
@@ -23,14 +23,14 @@ does **not** traverse the prototype chain.
2323

2424
Only `hasOwnProperty` will give the correct and expected result; this is
2525
essential when iterating over the properties of any object. There is **no** other
26-
way to exclude properties that are not defined on the object *itself*, but
26+
way to exclude properties that are not defined on the object itself, but
2727
somewhere on its prototype chain.
2828

2929
### `hasOwnProperty` as a Property
3030

31-
JavaScript does **not** protect the property name `hasOwnProperty`; thus, if the
31+
JavaScript does not protect the property name `hasOwnProperty`; thus, if the
3232
possibility exists that an object might have a property with this name, it is
33-
necessary to use an *external* `hasOwnProperty` in order to get correct results.
33+
necessary to use an *external* `hasOwnProperty` to get correct results.
3434

3535
var foo = {
3636
hasOwnProperty: function() {
@@ -44,14 +44,14 @@ necessary to use an *external* `hasOwnProperty` in order to get correct results.
4444
// Use another Object's hasOwnProperty and call it with 'this' set to foo
4545
({}).hasOwnProperty.call(foo, 'bar'); // true
4646

47-
// It's also possible use the hasOwnProperty property from the Object property for this purpose
47+
// It's also possible to use the hasOwnProperty property from the Object property for this purpose
4848
Object.prototype.hasOwnProperty.call(obj, 'bar'); // true
4949

5050

5151
### In Conclusion
5252

53-
When checking for the existence of a property on a object, `hasOwnProperty` is
54-
the **only** method of doing so. It is also recommended to make `hasOwnProperty`
55-
part of **every** [`for in` loop](#object.forinloop); this will avoid errors from
53+
Using `hasOwnProperty` is the **only** reliable method to check for the
54+
existence of a property on an object. It is recommended that `hasOwnProperty`
55+
is used in **every** [`for in` loop](#object.forinloop) to avoid errors from
5656
extended native [prototypes](#object.prototype).
5757

doc/en/object/prototype.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ JavaScript does not feature a classical inheritance model; instead, it uses a
44
*prototypal* one.
55

66
While 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
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
@@ -64,7 +64,7 @@ its prototype; thus, all `Bar` instances will share the **same** `value` propert
6464
When accessing the properties of an object, JavaScript will traverse the
6565
prototype 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
6868
hasn'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

8990
Also, 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

9495
One mis-feature that is often used is to extend `Object.prototype` or one of the
9596
other built in prototypes.
9697

9798
This 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
99100
reason for cluttering built-in types with additional *non-standard* functionality.
100101

101102
The **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

Comments
 (0)