Skip to content

Commit 61924da

Browse files
committed
First step in order to redo the generated site
1 parent c69ecba commit 61924da

35 files changed

+2038
-485
lines changed
File renamed without changes.

doc/arrays.md renamed to doc/array/general.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
## Arrays
1+
## Array iteration and properties
22

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

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

1616
### Iteration
1717

doc/eval.md renamed to doc/core/eval.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ achieved **without** it.
2929

3030
### `eval` in disguise
3131

32-
The [timeout functions](#timeouts) `setTimeout` and `setInterval` can both take a string as
33-
their first argument. This string will **always** get executed in the global
34-
scope since `eval` is not being called directly in that case.
32+
The [timeout functions](#other.timeouts) `setTimeout` and `setInterval` can both
33+
take a string as their first argument. This string will **always** get executed
34+
in the global scope since `eval` is not being called directly in that case.
3535

3636
### Security issues
3737

File renamed without changes.

doc/undefined.md renamed to doc/core/undefined.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ necessary to retrieve the value of `undefined` in the first place.
3131

3232
In order to protect code against a possible overwritten `undefined` variable, a
3333
common technique used is to add an additional parameter to the encapsulation
34-
[anonymous wrapper](#scopes), which gets no argument passed to it.
34+
[anonymous wrapper](#function.scopes), which gets no argument passed to it.
3535

3636
var undefined = 123;
3737
(function(something, foo, undefined) {
File renamed without changes.

doc/closures.md renamed to doc/function/closures.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
One of JavaScript's most powerful features is the availability of *closures*,
44
this means that scopes **always** keep access to the outer scope they were
55
defined in. Since the only scope that JavaScript has is the
6-
[function scope](#scopes), all functions, by default, act as closures.
6+
[function scope](#function.scopes), all functions, by default, act as closures.
77

88
### Emulating private variables
99

@@ -67,7 +67,7 @@ the value of `i`.
6767
### Avoiding the reference problem
6868

6969
In order to copy the value of the loop its index variable, it is best to use an
70-
[anonymous wrapper](#scopes).
70+
[anonymous wrapper](#function.scopes).
7171

7272
for(var i = 0; i < 10; i++) {
7373
(function(e) {

doc/constructors.md renamed to doc/function/constructors.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Constructors in JavaScript are yet again different from many other languages. An
44
function call that is preceded by the `new` keyword acts as a constructor.
55

66
Inside the constructor (the called function) the value of `this` refers to a
7-
newly created `Object`. The [`prototype`](#prototype) of this **new** object is
8-
set to the `prototype` of the function object that was called.
7+
newly created `Object`. The [`prototype`](#object.prototype) of this **new**
8+
object is set to the `prototype` of the function object that was called.
99

1010
If the function that was called has no explicit `return` statement, then it
1111
implicitly returns the value of `this` (the new object). Otherwise it returns
@@ -27,8 +27,8 @@ created object to `Foo.prototype`.
2727

2828
Keep in mind that if you do not use the `new` keyword the function will **not**
2929
return a new object. While it might still work due to the workings of
30-
[`this`](#how-this-works-in-javascript) in JavaScript, it will use the *global*
31-
object as the value of `this`.
30+
[`this`](#function.this) in JavaScript, it will use the *global* object as the
31+
value of `this`.
3232

3333
### Factories
3434

@@ -51,7 +51,7 @@ explicitly return a value.
5151
Bar();
5252

5353
Both these calls return the exact same thing, a newly create object which
54-
has a property called `method` which is a [Closure](#closures-and-references).
54+
has a property called `method` which is a [Closure](#function.closures).
5555

5656
Also note that the call `new Bar()` does **not** affect the prototype of the
5757
returned object. While the prototype will be set on the newly created object,
@@ -85,7 +85,7 @@ object inside it.
8585
}
8686

8787
While the above is robust against forgetting to use `new` and makes the use of
88-
[private variables](#closures) certainly easier, it comes with some down sides.
88+
[private variables](#function.closures) certainly easier, it comes with some down sides.
8989

9090
1. It uses more memory since the created objects do **not** share the methods
9191
2. In order to inherit the factory needs to copy all the methods from another

doc/functions.md renamed to doc/function/general.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Functions
1+
## Function declarations and expressions
22

33
Functions in JavaScript are first class objects, which means that they can be
44
passed around like any other value. One common use of this feature is to pass
@@ -30,7 +30,7 @@ declaration - creates the variable `foo` before the actual execution of the code
3030
starts, `foo` is already defined when the script gets executed.
3131

3232
Since assignments only happens at runtime, the value of `Foo` will default
33-
to [undefined](#undefined) before the corresponding code is executed.
33+
to [undefined](#core.undefined) before the corresponding code is executed.
3434

3535
### Named function expression
3636

@@ -43,7 +43,7 @@ Another special case is the assignment of named functions.
4343

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

4949
### The `var` statement
@@ -62,8 +62,8 @@ is always made available in the local scope of the function itself.
6262
var foo = 1;
6363
}
6464

65-
Since there is **no** [block scope](#scopes) in JavaScript, the above will
66-
**not** assign the value `2` to the *global* variable `bar`. It will rather
65+
Since there is **no** [block scope](#function.scopes) in JavaScript, the above
66+
will **not** assign the value `2` to the *global* variable `bar`. It will rather
6767
assign the value of `2` to the *local* variable `bar` of `test`.
6868

6969
Also, while the statements inside the `if` block never get executed, the variable

doc/scopes.md renamed to doc/function/scopes.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ is in the language is *function scope*.
1414
> **Note:** When not used in an assignment, return statement or as a function
1515
> argument, the `{...}` notation will get interpreted as a block statement and
1616
> **not** as an object literal. This, in conjunction with
17-
> [automatic insertion of semicolons](#semicolon), can lead to subtle errors.
17+
> [automatic insertion of semicolons](#core.semicolon), can lead to subtle errors.
1818
1919
There are also no distinct namespaces in JavaScript. This means that everything
2020
gets defined in **one** globally shared namespace.
@@ -72,8 +72,9 @@ unless the desired effect **is** to affect the outer scope.
7272

7373
### Local variables
7474

75-
The only source for local variables in JavaScript are [function](#functions)
76-
parameters and variables that were declared via the `var` statement.
75+
The only source for local variables in JavaScript are
76+
[function](#function.general) parameters and variables that were declared via the
77+
`var` statement.
7778

7879
// global scope
7980
var foo = 1;
@@ -95,9 +96,9 @@ the assignment of `bar` will override the global variable with the same name.
9596
### Name resolution order
9697

9798
All scopes in JavaScript - including the global one - have the name
98-
[this](#this) defined in them, which refers to the "current object".
99+
[this](#function.this) defined in them, which refers to the "current object".
99100

100-
Function scopes also have the name [arguments](#arguments) defined, which
101+
Function scopes also have the name [arguments](#function.arguments) defined, which
101102
contains the arguments that were passed to a function.
102103

103104
For example, when trying to access a variable named `foo` inside the scope of a
@@ -127,8 +128,8 @@ easily avoided with the help of anonymous *function wrappers*.
127128
})(); // execute the function immediately
128129

129130

130-
Unnamed functions are considered [expressions](#functions); so in order to being
131-
callable, they must first be evaluated.
131+
Unnamed functions are considered [expressions](#function.general); so in order to
132+
being callable, they must first be evaluated.
132133

133134
( // evaluate the function inside the paranthesis
134135
function() {}

doc/this.md renamed to doc/function/this.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## How `this` works
22

33
JavaScript has a different concept of what `this` refers to than most other
4-
languages do. There are exactly **five** different ways in which the value of `this`
5-
can be bound in the language.
4+
languages do. There are exactly **five** different ways in which the value of
5+
`this` can be bound in the language.
66

77
### The global scope
88

@@ -17,8 +17,8 @@ When using `this` in global scope, it will simply refer to the *global* object.
1717

1818
Here `this` will again refer to the *global* object.
1919

20-
> **ES5 Note:** In strict mode, `this` will **no longer** refer to the global object.
21-
> It will instead have the value of `undefined`.
20+
> **ES5 Note:** In strict mode, `this` will **no longer** refer to the global
21+
> object. It will instead have the value of `undefined`.
2222
2323
### Calling a method
2424

@@ -31,8 +31,8 @@ In this example `this` will refer to `test`.
3131
new foo();
3232

3333
A function call that is preceded by the `new` keyword acts as
34-
a [constructor](#constructors). Inside the function `this` will refer to a newly
35-
created `Object`.
34+
a [constructor](#function.constructors). Inside the function `this` will refer
35+
to a newly created `Object`.
3636

3737
### Explicit setting of `this`
3838

@@ -80,8 +80,8 @@ local variable inside of `method` which refers to `Foo`.
8080
}
8181

8282
`that` is just a normal name, but it is commonly used for the reference to an
83-
outer `this`. In combination with [closures](#closures), it can also be used to
84-
pass `this` values around.
83+
outer `this`. In combination with [closures](#function.closures), it can also
84+
be used to pass `this` values around.
8585

8686
### Assigning methods
8787

@@ -95,7 +95,7 @@ Again due to the first case `test` now acts like like a plain function call;
9595
therefore, `this` inside it will no longer refer to `someObject`.
9696

9797
While the late binding of `this` might seem like a bad idea, it is in fact what
98-
makes [prototypical inheritance](#prototype) work.
98+
makes [prototypical inheritance](#object.prototype) work.
9999

100100
function Foo() {}
101101
Foo.prototype.method = function() {};

doc/globals.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

doc/index.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"title": "JavaScript Garden",
3+
"description": "A Guide to JavaScript's Quirks and Flaws.",
4+
"sections": [
5+
{
6+
"title": "Intro",
7+
"dir": "intro"
8+
},
9+
{
10+
"title": "Objects",
11+
"dir": "object",
12+
"articles": [
13+
"general",
14+
"prototype",
15+
"hasownproperty",
16+
"forinloop"
17+
]
18+
},
19+
{
20+
"title": "Functions",
21+
"dir": "function",
22+
"articles": [
23+
"general",
24+
"this",
25+
"closures",
26+
"arguments",
27+
"constructors",
28+
"scopes"
29+
]
30+
},
31+
{
32+
"title": "Arrays",
33+
"dir": "array",
34+
"articles": [
35+
"general",
36+
"constructor"
37+
]
38+
},
39+
{
40+
"title": "Types",
41+
"dir": "types",
42+
"articles": [
43+
"equality",
44+
"typeof",
45+
"instanceof",
46+
"casting"
47+
]
48+
},
49+
{
50+
"title": "Core",
51+
"dir": "core",
52+
"articles": [
53+
"eval",
54+
"undefined",
55+
"semicolon"
56+
]
57+
},
58+
{
59+
"title": "Other",
60+
"dir": "other",
61+
"articles": [
62+
"timeouts"
63+
]
64+
}
65+
]
66+
}

doc/index.md

Lines changed: 0 additions & 24 deletions
This file was deleted.
File renamed without changes.

doc/forinloop.md renamed to doc/object/forinloop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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 itself,
20-
this is done by using the [`hasOwnProperty`](#hasownproperty) method of
20+
this is done by using the [`hasOwnProperty`](#object.hasownproperty) method of
2121
objects.
2222

2323
> **Note:** Since the `for in` always traverses the complete prototype chain, it

doc/objects.md renamed to doc/object/general.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
## Objects
1+
## Object usage and properties
22

33
Everything in JavaScript acts like an object, with the only two exceptions being
4-
[`null`](#undefined) and [`undefined`](#undefined).
4+
[`null`](#core.undefined) and [`undefined`](#core.undefined).
55

66
false.toString() // 'false'
77
[1, 2, 3].toString(); // '1,2,3'
@@ -29,8 +29,8 @@ Objects in JavaScript can also be used as a [*Hashmap*][1], they mainly consist
2929
of named properties mapping to values.
3030

3131
Using the curly brace notation `{}` one can create a plain object. This new
32-
object [inherits](#prototype) from `Object.prototype` and has no
33-
[own properties](#hasownproperty) defined on it.
32+
object [inherits](#object.prototype) from `Object.prototype` and has no
33+
[own properties](#object.hasownproperty) defined on it.
3434

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

@@ -96,3 +96,4 @@ therefore, it must be notated as a string literal in order to ensure working
9696
code under older JavaScript engines.
9797

9898
[1]: http://en.wikipedia.org/wiki/Hashmap
99+

doc/hasownproperty.md renamed to doc/object/hasownproperty.md

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

33
In order to check whether a object has a property defined on itself and **not**
4-
somewhere on its [prototype chain](#prototype), it is necessary to use the
4+
somewhere 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
@@ -30,6 +30,6 @@ somewhere on its prototype chain.
3030

3131
When checking for the existence of a property on a object, `hasOwnProperty` is
3232
the **only** method of doing so. It is also recommended to make `hasOwnProperty`
33-
part of **every** [`for in` loop](#forinloop), this will avoid errors from
34-
extended native [prototypes](#prototype).
33+
part of **every** [`for in` loop](#object.forinloop), this will avoid errors from
34+
extended native [prototypes](#object.prototype).
3535

0 commit comments

Comments
 (0)