Skip to content

Commit 076cf14

Browse files
committed
Merge pull request BonsaiDen#98 from XP1/master
Fix a lot of English grammar mistakes. Include English recommendations.
2 parents 008c08d + 02ff4f6 commit 076cf14

21 files changed

+114
-115
lines changed

doc/en/array/constructor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ when creating new arrays.
1111
new Array(3); // Result: []
1212
new Array('3') // Result: ['3']
1313

14-
In cases when there is only one argument passed to the `Array` constructor,
15-
and that argument is a `Number`, the constructor will return a new *sparse*
14+
In cases when there is only one argument passed to the `Array` constructor
15+
and when that argument is a `Number`, the constructor will return a new *sparse*
1616
array with the `length` property set to the value of the argument. It should be
17-
noted that **only** the `length` property of the new array will be set this way,
17+
noted that **only** the `length` property of the new array will be set this way;
1818
the actual indexes of the array will not be initialized.
1919

2020
var arr = new Array(3);

doc/en/array/general.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
## Array Iteration and Properties
22

33
Although arrays in JavaScript are objects, there are no good reasons to use
4-
the [`for in loop`](#object.forinloop) in for iteration on them. In fact there
4+
the [`for in loop`](#object.forinloop) in for iteration on them. In fact, there
55
are a number of good reasons **against** the use of `for in` on arrays.
66

77
> **Note:** JavaScript arrays are **not** *associative arrays*. JavaScript only
88
> has [objects](#object.general) for mapping keys to values. And while associative
99
> arrays **preserve** order, objects **do not**.
1010
11-
Since the `for in` loop enumerates all the properties that are on the prototype
12-
chain and the only way to exclude those properties is to use
11+
Because the `for in` loop enumerates all the properties that are on the prototype
12+
chain and because the only way to exclude those properties is to use
1313
[`hasOwnProperty`](#object.hasownproperty), it is already up to **twenty times**
1414
slower than a normal `for` loop.
1515

@@ -23,7 +23,7 @@ to use the classic `for` loop.
2323
console.log(list[i]);
2424
}
2525

26-
There is one extra catch in the above example, that is the caching of the
26+
There is one extra catch in the above example, which is the caching of the
2727
length of the array via `l = list.length`.
2828

2929
Although the `length` property is defined on the array itself, there is still an
@@ -52,7 +52,7 @@ does not have any effect on the array.
5252

5353
### In Conclusion
5454

55-
For the best performance it is recommended to always use the plain `for` loop
55+
For the best performance, it is recommended to always use the plain `for` loop
5656
and cache the `length` property. The use of `for in` on an array is a sign of
5757
badly written code that is prone to bugs and bad performance.
5858

doc/en/core/eval.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ The `eval` function will execute a string of JavaScript code in the local scope.
1111
test(); // 3
1212
foo; // 1
1313

14-
But `eval` only executes in local scope when it is being called **directly** *and*
15-
the name of the called function is actually `eval`.
14+
However, `eval` only executes in the local scope when it is being called
15+
**directly** *and* when the name of the called function is actually `eval`.
1616

1717
var foo = 1;
1818
function test() {
@@ -35,14 +35,13 @@ in the global scope since `eval` is not being called directly in that case.
3535

3636
### Security Issues
3737

38-
`eval` also is a security problem as it executes **any** code given to it,
38+
`eval` also is a security problem. Because it executes **any** code given to it,
3939
it should **never** be used with strings of unknown or untrusted origins.
4040

4141
### In Conclusion
4242

43-
`eval` should never be used, any code that makes use of it is to be questioned in
43+
`eval` should never be used. Any code that makes use of it is to be questioned in
4444
its workings, performance and security. In case something requires `eval` in
45-
order to work, its design is to be questioned and should **not** be used in the
46-
first place, a *better design* should be used, that does not require the use of
47-
`eval`.
45+
order to work, it should **not** be used in the first place.
46+
A *better design* should be used, that does not require the use of `eval`.
4847

doc/en/core/semicolon.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Automatic Semicolon Insertion
22

33
Although JavaScript has C style syntax, it does **not** enforce the use of
4-
semicolons in the source code, it is possible to omit them.
4+
semicolons in the source code, so it is possible to omit them.
55

6-
But JavaScript is not a semicolon-less language, it in fact needs the
7-
semicolons in order to understand the source code. Therefore the JavaScript
6+
JavaScript is not a semicolon-less language. In fact, it needs the
7+
semicolons in order to understand the source code. Therefore, the JavaScript
88
parser **automatically** inserts them whenever it encounters a parse
99
error due to a missing semicolon.
1010

@@ -19,7 +19,7 @@ Insertion happens, and the parser tries again.
1919
test()
2020

2121
The automatic insertion of semicolon is considered to be one of **biggest**
22-
design flaws in the language, as it *can* change the behavior of code.
22+
design flaws in the language because it *can* change the behavior of code.
2323

2424
### How it Works
2525

@@ -87,7 +87,7 @@ Below is the result of the parser's "guessing" game.
8787
> which are followed by a new line, while this is not neccessarily the fault of
8888
> the automatic semicolon insertion, it can still be an unwanted side-effect.
8989
90-
The parser drastically changed the behavior of the code above, in certain cases
90+
The parser drastically changed the behavior of the code above. In certain cases,
9191
it does the **wrong thing**.
9292

9393
### Leading Parenthesis
@@ -106,9 +106,9 @@ the above will yield a `TypeError` stating that `undefined is not a function`.
106106

107107
### In Conclusion
108108

109-
It is highly recommended to **never** omit semicolons, it is also advocated to
109+
It is highly recommended to **never** omit semicolons; it is also advocated to
110110
keep braces on the same line with their corresponding statements and to never omit
111111
them for one single-line `if` / `else` statements. Both of these measures will
112-
not only improve the consistency of the code, they will also prevent the
112+
not only improve the consistency of the code, but they will also prevent the
113113
JavaScript parser from changing its behavior.
114114

doc/en/core/undefined.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ being `undefined`.
77

88
`undefined` is a type with exactly one value: `undefined`.
99

10-
The language also defines a global variable that has the value of `undefined`,
11-
this variable is also called `undefined`. But this variable is **not** a constant,
12-
nor is it a keyword of the language. This means that its *value* can be easily
10+
The language also defines a global variable that has the value of `undefined`;
11+
this variable is also called `undefined`. However, this variable is **neither** a constant
12+
nor a keyword of the language. This means that its *value* can be easily
1313
overwritten.
1414

1515
> **ES5 Note:** `undefined` in ECMAScript 5 is **no longer** *writable* in strict
@@ -31,12 +31,12 @@ Since the global variable `undefined` only holds a copy of the actual *value* of
3131
`undefined`, assigning a new value to it does **not** change the value of the
3232
*type* `undefined`.
3333

34-
Still, in order to compare something against the value of `undefined` it is
34+
Still, in order to compare something against the value of `undefined`, it is
3535
necessary to retrieve the value of `undefined` first.
3636

3737
In order to protect code against a possible overwritten `undefined` variable, a
3838
common technique used is to add an additional parameter to an
39-
[anonymous wrapper](#function.scopes), that gets no argument passed to it.
39+
[anonymous wrapper](#function.scopes) that gets no argument passed to it.
4040

4141
var undefined = 123;
4242
(function(something, foo, undefined) {
@@ -55,8 +55,8 @@ wrapper.
5555

5656
})('Hello World', 42);
5757

58-
The only difference being here, that this version results in 4 more bytes being
59-
used in case it is minified and there is no other `var` statement inside the
58+
The only difference here is that this version results in 4 more bytes being
59+
used in case it is minified, and there is no other `var` statement inside the
6060
anonymous wrapper.
6161

6262
### Uses of `null`
@@ -66,7 +66,7 @@ the sense of a traditional *null*, the actual `null` (both a literal and a type)
6666
is more or less just another data type.
6767

6868
It is used in some JavaScript internals (like declaring the end of the
69-
prototype chain by setting `Foo.prototype = null`), but in almost all cases it
69+
prototype chain by setting `Foo.prototype = null`), but in almost all cases, it
7070
can be replaced by `undefined`.
7171

7272

doc/en/function/arguments.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ The code below will return a new `Array` containing all the elements of the
2323

2424
Array.prototype.slice.call(arguments);
2525

26-
This conversion is **slow**, it is **not recommended** to use it in performance
27-
critical sections of code.
26+
Because this conversion is **slow**, it is **not recommended** to use it in
27+
performance-critical sections of code.
2828

2929
### Passing Arguments
3030

@@ -59,7 +59,7 @@ wrappers.
5959
### Formal Parameters and Arguments Indices
6060

6161
The `arguments` object creates *getter* and *setter* functions for both its
62-
properties as well as the function's formal parameters.
62+
properties, as well as the function's formal parameters.
6363

6464
As a result, changing the value of a formal parameter will also change the value
6565
of the corresponding property on the `arguments` object, and the other way around.
@@ -105,8 +105,8 @@ modern JavaScript engines. That case is the use of `arguments.callee`.
105105

106106
In the above code, `foo` can no longer be a subject to [inlining][1] since it
107107
needs to know about both itself and its caller. This not only defeats possible
108-
performance gains that would arise from inlining, it also breaks encapsulation
109-
since the function may now be dependent on a specific calling context.
108+
performance gains that would arise from inlining, but it also breaks encapsulation
109+
because the function may now be dependent on a specific calling context.
110110

111111
It is **highly recommended** to **never** make use of `arguments.callee` or any of
112112
its properties.

doc/en/function/closures.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Closures and References
22

3-
One of JavaScript's most powerful features is the availability of *closures*,
4-
this means that scopes **always** keep access to the outer scope they were
5-
defined in. Since the only scoping that JavaScript has is
3+
One of JavaScript's most powerful features is the availability of *closures*.
4+
With closures, scopes **always** keep access to the outer scope, in which they
5+
were defined. Since the only scoping that JavaScript has is
66
[function scope](#function.scopes), all functions, by default, act as closures.
77

88
### Emulating private variables
@@ -24,7 +24,7 @@ defined in. Since the only scoping that JavaScript has is
2424
foo.increment();
2525
foo.get(); // 5
2626

27-
Here, `Counter` returns **two** closures. The function `increment` as well as
27+
Here, `Counter` returns **two** closures: the function `increment` as well as
2828
the function `get`. Both of these functions keep a **reference** to the scope of
2929
`Counter` and, therefore, always keep access to the `count` variable that was
3030
defined in that very scope.
@@ -58,8 +58,8 @@ copying the value of the loops index variable.
5858
The above will **not** output the numbers `0` through `9`, but will simply print
5959
the number `10` ten times.
6060

61-
The *anonymous* function keeps a **reference** to `i` and at the time
62-
`console.log` gets called, the `for loop` has already finished and the value of
61+
The *anonymous* function keeps a **reference** to `i`. At the time
62+
`console.log` gets called, the `for loop` has already finished, and the value of
6363
`i` as been set to `10`.
6464

6565
In order to get the desired behavior, it is necessary to create a **copy** of
@@ -84,8 +84,8 @@ argument and will receive a copy of the **value** of `i` as its parameter `e`.
8484
The anonymous function that gets passed to `setTimeout` now has a reference to
8585
`e`, whose value does **not** get changed by the loop.
8686

87-
There is another possible way of achieving this; that is to return a function
88-
from the anonymous wrapper, that will then have the same behavior as the code
87+
There is another possible way of achieving this, which is to return a function
88+
from the anonymous wrapper that will then have the same behavior as the code
8989
above.
9090

9191
for(var i = 0; i < 10; i++) {

doc/en/function/constructors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ implicitly returns the value of `this` - the new object.
2424
The above calls `Foo` as constructor and sets the `prototype` of the newly
2525
created object to `Foo.prototype`.
2626

27-
In case of an explicit `return` statement the function returns the value
27+
In case of an explicit `return` statement, the function returns the value
2828
specified that statement, **but only** if the return value is an `Object`.
2929

3030
function Bar() {
@@ -73,7 +73,7 @@ explicitly return a value.
7373
Bar();
7474

7575
Both calls to `Bar` return the exact same thing, a newly create object which
76-
has a property called `method` on it, that is a
76+
has a property called `method` on it, which is a
7777
[Closure](#function.closures).
7878

7979
It is also to note that the call `new Bar()` does **not** affect the prototype
@@ -86,7 +86,7 @@ not using the `new` keyword.
8686

8787
### Creating New Objects via Factories
8888

89-
An often made recommendation is to **not** use `new` since forgetting its use
89+
An often made recommendation is to **not** use `new` because forgetting its use
9090
may lead to bugs.
9191

9292
In order to create new object, one should rather use a factory and construct a

doc/en/function/general.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This example assigns the unnamed and *anonymous* function to the variable `foo`.
2525
foo(); // this raises a TypeError
2626
var foo = function() {};
2727

28-
Due to the fact that `var` is a declaration, that hoists the variable name `foo`
28+
Due to the fact that `var` is a declaration that hoists the variable name `foo`
2929
before the actual execution of the code starts, `foo` is already defined when
3030
the script gets executed.
3131

@@ -41,8 +41,8 @@ Another special case is the assignment of named functions.
4141
}
4242
bar(); // ReferenceError
4343

44-
Here `bar` is not available in the outer scope, since the function only gets
45-
assigned to `foo`; however, inside of `bar` it is available. This is due to
44+
Here, `bar` is not available in the outer scope, since the function only gets
45+
assigned to `foo`; however, inside of `bar`, it is available. This is due to
4646
how [name resolution](#function.scopes) in JavaScript works, the name of the
4747
function is *always* made available in the local scope of the function itself.
4848

doc/en/function/scopes.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ is in the language is *function scope*.
1616
> **not** as an object literal. This, in conjunction with
1717
> [automatic insertion of semicolons](#core.semicolon), can lead to subtle errors.
1818
19-
There are also no distinct namespaces in JavaScript, that means that everything
19+
There are also no distinct namespaces in JavaScript, which means that everything
2020
gets defined in one *globally shared* namespace.
2121

2222
Each time a variable is referenced, JavaScript will traverse upwards through all
@@ -32,10 +32,10 @@ still has not found the requested name, it will raise a `ReferenceError`.
3232
var foo = '42'
3333

3434
The above two scripts do **not** have the same effect. Script A defines a
35-
variable called `foo` in the *global* scope and script B defines a `foo` in the
35+
variable called `foo` in the *global* scope, and script B defines a `foo` in the
3636
*current* scope.
3737

38-
Again, that is **not** at all the *same effect*, not using `var` can have major
38+
Again, that is **not** at all the *same effect*: not using `var` can have major
3939
implications.
4040

4141
// global scope
@@ -49,8 +49,8 @@ implications.
4949

5050
Leaving out the `var` statement inside the function `test` will override the
5151
value of `foo`. While this might not seem like a big deal at first, having
52-
thousands of lines of JavaScript and not using `var` will introduce horrible and
53-
hard to track down bugs.
52+
thousands of lines of JavaScript and not using `var` will introduce horrible,
53+
hard-to-track-down bugs.
5454

5555
// global scope
5656
var items = [/* some list */];
@@ -116,7 +116,7 @@ JavaScript **hoists** declarations. This means that both `var` statements and
116116
}
117117

118118
The above code gets transformed before any execution is started. JavaScript moves
119-
the `var` statements as well as the `function` declarations to the top of the
119+
the `var` statements, as well as the `function` declarations to the top of the
120120
nearest surrounding scope.
121121

122122
// var statements got moved here
@@ -146,11 +146,11 @@ Missing block scoping will not only move `var` statements out of loops and
146146
their bodies, it will also make the results of certain `if` constructs
147147
non-intuitive.
148148

149-
In the original code the `if` statement seemed to modify the *global
150-
variable* `goo`, while actually it modifies the *local variable* - after hoisting
149+
In the original code, although the `if` statement seemed to modify the *global
150+
variable* `goo`, it actually modifies the *local variable* - after hoisting
151151
has been applied.
152152

153-
Without the knowledge about *hoisting*, below code might seem to raise a
153+
Without the knowledge about *hoisting*, the below code might seem to raise a
154154
`ReferenceError`.
155155

156156
// check whether SomeImportantThing has been initiliazed
@@ -173,18 +173,18 @@ moved to the top of the *global scope*.
173173
### Name Resolution Order
174174

175175
All scopes in JavaScript, including the *global scope*, have the special name
176-
[`this`](#function.this) defined in them, which refers to the *current object*.
176+
[`this`](#function.this), defined in them, which refers to the *current object*.
177177

178-
Function scopes also have the name [`arguments`](#function.arguments) defined in
179-
them which contains the arguments that were passed to a function.
178+
Function scopes also have the name [`arguments`](#function.arguments), defined in
179+
them, which contains the arguments that were passed to a function.
180180

181181
For example, when trying to access a variable named `foo` inside the scope of a
182182
function, JavaScript will lookup the name in the following order:
183183

184-
1. In case there is a `var foo` statement in the current scope use that.
185-
2. If one of the function parameters is named `foo` use that.
186-
3. If the function itself is called `foo` use that.
187-
4. Go to the next outer scope and start with **#1** again.
184+
1. In case there is a `var foo` statement in the current scope, use that.
185+
2. If one of the function parameters is named `foo`, use that.
186+
3. If the function itself is called `foo`, use that.
187+
4. Go to the next outer scope, and start with **#1** again.
188188

189189
> **Note:** Having a parameter called `arguments` will **prevent** the creation
190190
> of the default `arguments` object.
@@ -223,7 +223,7 @@ while different in syntax, do behave the exact same way.
223223
### In Conclusion
224224

225225
It is recommended to always use an *anonymous wrapper* for encapsulating code in
226-
its own namespace. This does not only protect code against name clashes, it
226+
its own namespace. This does not only protect code against name clashes, but it
227227
also allows for better modularization of programs.
228228

229229
Additionally, the use of global variables is considered **bad practice**. **Any**

0 commit comments

Comments
 (0)