Skip to content

Commit a8f40a0

Browse files
committed
merge with upstream
2 parents 12e34fc + a8259ce commit a8f40a0

File tree

172 files changed

+7926
-694
lines changed

Some content is hidden

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

172 files changed

+7926
-694
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
/site/zh
1010
/site/en
1111
/site/fi
12+
/site/pl
1213
/site/tr
14+
/site/ko
15+
/site/ja
16+
/site/es
17+
/site/zhtw
1318
*.md~
1419
*.src.md
20+
*.DS_store

build.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var fs = require('fs'),
2-
path = require('path');
2+
path = require('path'),
33
jade = require('jade'),
44
md = require('node-markdown'),
55
Class = require('neko').Class;
@@ -28,10 +28,10 @@ var Garden = Class(function(options) {
2828

2929
if (that.loadIndex()) {
3030
that.languages[lang] = that.lang;
31-
that.log(' Done.')
31+
that.log(' Done.');
3232

3333
} else {
34-
that.log(' Error: Could not find "index.json"!')
34+
that.log(' Error: Could not find "index.json"!');
3535
}
3636
}
3737
});
@@ -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/de/intro/index.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
## Einführung
22

3-
Demnächst.
3+
**JavaScript Garden** ist eine wachsende Sammlung von Erklärungen der verzwicktesten Teile von JavaScript. Es gibt
4+
Hinweise um häufige Fehler, Performance Probleme und schlechten Stil zu vermeiden.
45

6+
JavaScript Garden ist **keine** Anleitung um JavaScript zu lernen. Ein grundlegendes Verständnis der Sprache wird
7+
wärmstens empfohlen. Eine gute [Einführung][1] findet sich zum Beispiel im Mozilla Developer Network.
8+
9+
## Die Autoren
10+
11+
Dieses Dokument wurde von zwei liebenswerten [Stack Overflow][2] Benutzern geschrieben: [Ivo Wetzel][3]
12+
(Text) and [Zhang Yi Jiang][4] (Design).
13+
14+
## Beitragende
15+
16+
- [Caio Romão][5] (Rechtschreibung)
17+
- [Andreas Blixt][6] (Sprachanpassungen)
18+
19+
## Hosting
20+
21+
JavaScript Garden wird von GitHub bereitgestellt, aber es wird auch von [Cramer Development][7] unterstützt durch
22+
einen Mirror auf [JavaScriptGarden.info][8].
23+
24+
## Lizenz
25+
26+
JavaScript Garden wurde unter der [MIT Lizenz][9] veröffentlich und wird von [GitHub][10] veröffentlicht. Wenn du
27+
Fehler findest mach bitte ein [Ticket][11] auf oder einen pull request ins repository. Du kannst uns auch im
28+
[JavaScript Raum][12] des Stack Overflow Chats finden.
29+
30+
Mehr demnächst.
31+
32+
[1]: https://developer.mozilla.org/en/JavaScript/Guide
33+
[2]: http://stackoverflow.com/
34+
[3]: http://stackoverflow.com/users/170224/ivo-wetzel
35+
[4]: http://stackoverflow.com/users/313758/yi-jiang
36+
[5]: https://github.com/caio
37+
[6]: https://github.com/blixt
38+
[7]: http://cramerdev.com/
39+
[8]: http://javascriptgarden.info/
40+
[9]: https://github.com/BonsaiDen/JavaScript-Garden/blob/next/LICENSE
41+
[10]: https://github.com/BonsaiDen/JavaScript-Garden
42+
[11]: https://github.com/BonsaiDen/JavaScript-Garden/issues
43+
[12]: http://chat.[stackoverflow.com/rooms/17/javascript

doc/en/array/constructor.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ 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);
2121
arr[1]; // undefined
2222
1 in arr; // false, the index was not set
2323

24-
The behavior of being able to set the length of the array upfront only comes in
25-
handy in a few cases, like repeating a string, in which it avoids the use of a
26-
`for loop` code.
24+
Being able to set the length of the array in advance is only useful in a few
25+
cases, like repeating a string, in which it avoids the use of a `for loop`
26+
code.
2727

2828
new Array(count + 1).join(stringToRepeat);
2929

3030
### In Conclusion
3131

32-
The use of the `Array` constructor should be avoided as much as possible.
33-
Literals are definitely preferred. They are shorter and have a clearer syntax;
34-
therefore, they also increase the readability of the code.
32+
The use of the `Array` constructor should be avoided. Literals are definitely
33+
preferred. They are shorter, have a clearer syntax, and increase code
34+
readability.
3535

doc/en/array/general.md

Lines changed: 8 additions & 8 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`](#object.forinloop) loop. 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
@@ -45,14 +45,14 @@ elements that are contained in the array, the *setter* can be used to
4545
foo; // [1, 2, 3]
4646

4747
foo.length = 6;
48-
foo; // [1, 2, 3]
48+
foo.push(4);
49+
foo; // [1, 2, 3, undefined, undefined, undefined, 4]
4950

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

doc/en/core/eval.md

Lines changed: 10 additions & 11 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() {
@@ -24,8 +24,8 @@ the name of the called function is actually `eval`.
2424
test(); // 2
2525
foo; // 3
2626

27-
The use of `eval` should be avoided at **all costs**. 99.9% of its "uses" can be
28-
achieved **without** it.
27+
The use of `eval` should be avoided. 99.9% of its "uses" can be achieved
28+
**without** it.
2929

3030
### `eval` in Disguise
3131

@@ -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,
39-
it should **never** be used with strings of unknown or untrusted origins.
38+
`eval` also is a security problem, because it executes **any** code given to it.
39+
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
44-
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`.
43+
`eval` should never be used. Any code that makes use of it should be questioned
44+
in its workings, performance and security. If something requires `eval` in
45+
order to work, it should **not** be used in the first place. A *better design*
46+
should be used, that does not require the use of `eval`.
4847

doc/en/core/semicolon.md

Lines changed: 11 additions & 11 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

@@ -84,10 +84,10 @@ Below is the result of the parser's "guessing" game.
8484
})(window); //<- inserted
8585

8686
> **Note:** The JavaScript parser does not "correctly" handle return statements
87-
> which are followed by a new line, while this is not neccessarily the fault of
87+
> that 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
110-
keep braces on the same line with their corresponding statements and to never omit
111-
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
113-
JavaScript parser from changing its behavior.
109+
It is highly recommended to **never** omit semicolons. It is also recommended
110+
that braces be kept on the same line as their corresponding statements and to
111+
never omit them for single-line `if` / `else` statements. These measures will
112+
not only improve the consistency of the code, but they will also prevent the
113+
JavaScript parser from changing code behavior.
114114

0 commit comments

Comments
 (0)