Skip to content

Commit a8022ab

Browse files
committed
Merge commit 'bonsaiden/master'
Conflicts: server.js site/pl/index.html
2 parents 95cf32f + 91ca3bd commit a8022ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+549
-464
lines changed

build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ var Garden = Class(function(options) {
164164
top: lang.navigation[0]
165165
};
166166

167-
jade.renderFile(template, {locals: options}, function(err, html){
168-
if (err) throw err;
169-
fs.writeFileSync(out, html);
170-
});
167+
var jadefile = fs.readFileSync(template);
168+
var jadetemplate = jade.compile (jadefile);
169+
var html = jadetemplate(options);
170+
fs.writeFileSync(out, html);
171171
this.log(' Done.');
172172
}
173173
},

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/delete.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## The `delete` Operator
2+
3+
In short, it's *impossible* to delete global variables, functions and some other
4+
stuff in JavaScript which have a `DontDelete` attribute set.
5+
6+
### Global code and Function code
7+
8+
When a variable or a function is defined in a global
9+
or a [function scope](#function.scopes) it is a property of either
10+
Activation object or Global object. Such properties have a set of attributes,
11+
one of these is `DontDelete`. Variable and function declarations in global
12+
and function code always create properties with `DontDelete`, therefore
13+
cannot be deleted.
14+
15+
// global variable:
16+
var a = 1; // DontDelete is set
17+
delete a; // false
18+
a; // 1
19+
20+
// normal function:
21+
function f() {} // DontDelete is set
22+
delete f; // false
23+
typeof f; // "function"
24+
25+
// reassigning doesn't help:
26+
f = 1;
27+
delete f; // false
28+
f; // 1
29+
30+
### Explicit properties
31+
32+
There are things which can be deleted normally: these are explicitly set
33+
properties.
34+
35+
// explicitly set property:
36+
var obj = {x: 1};
37+
obj.y = 2;
38+
delete obj.x; // true
39+
delete obj.y; // true
40+
obj.x; // undefined
41+
obj.y; // undefined
42+
43+
In the example above `obj.x` and `obj.y` can be deleted because they have no
44+
`DontDelete` atribute. That's why an example below works too.
45+
46+
// this works fine, except for IE:
47+
var GLOBAL_OBJECT = this;
48+
GLOBAL_OBJECT.a = 1;
49+
a === GLOBAL_OBJECT.a; // true - just a global var
50+
delete GLOBAL_OBJECT.a; // true
51+
GLOBAL_OBJECT.a; // undefined
52+
53+
Here we use a trick to delete `a`. [`this`](#function.this) here refers
54+
to the Global object and we explicitly declare variable `a` as it's property
55+
which allows us to delete it.
56+
57+
IE (at least 6-8) has some bugs, so code above doesn't work.
58+
59+
### Function arguments and built-ins
60+
61+
Functions' normal arguments, [`arguments` object](#function.arguments)
62+
and built-in properties also have `DontDelete` set.
63+
64+
// function arguments and properties:
65+
(function (x) {
66+
67+
delete arguments; // false
68+
typeof arguments; // "object"
69+
70+
delete x; // false
71+
x; // 1
72+
73+
function f(){}
74+
delete f.length; // false
75+
typeof f.length; // "number"
76+
77+
})(1);
78+
79+
### Host objects
80+
81+
Behaviour of `delete` operator can be unpredictable for hosted objects. Due to
82+
specification, host objects are allowed to implement any kind of behavior.
83+
84+
### In conclusion
85+
86+
`delete` operator often has an unexpected behaviour and can be safely used
87+
only for dealing with explicitly set properties on normal objects.

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: 6 additions & 6 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,14 +59,14 @@ 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.
6666

6767
function foo(a, b, c) {
6868
arguments[0] = 2;
69-
a; // 2
69+
a; // 2
7070

7171
b = 4;
7272
arguments[1]; // 4
@@ -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

0 commit comments

Comments
 (0)