Skip to content

Commit 3798cbb

Browse files
committed
merge with upstream/master
2 parents 391df07 + 31c5a75 commit 3798cbb

Some content is hidden

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

99 files changed

+5518
-73
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
/site/ru
88
/site/en
99
/site/zh
10+
/site/en
11+
/site/fi
12+
/site/tr
1013
*.md~
1114
*.src.md

doc/en/function/this.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local variable inside of `method` which refers to `Foo`.
7979
test();
8080
}
8181

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

@@ -91,7 +91,7 @@ Another thing that does **not** work in JavaScript is function aliasing, that is
9191
var test = someObject.methodTest;
9292
test();
9393

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

9797
While the late binding of `this` might seem like a bad idea at first, it is in

doc/en/index.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
{
77
"title": "Intro",
88
"dir": "intro",
9-
"articles": [
10-
"authors",
11-
"contributors",
12-
"hosting",
13-
"license"
14-
]
9+
"articles": []
1510
},
1611
{
1712
"title": "Objects",

doc/en/intro/authors.md

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

doc/en/intro/contributors.md

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

doc/en/intro/hosting.md

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

doc/en/intro/index.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,37 @@ of the language is strongly recommended in order to understand the topics covere
1111
in this guide. In order to learn the basics of the language, please head over to
1212
the excellent [guide][1] on the Mozilla Developer Network.
1313

14-
[1]: https://developer.mozilla.org/en/JavaScript/Guide
14+
## The Authors
15+
16+
This guide is the work of two lovely [Stack Overflow][2] users, [Ivo Wetzel][3]
17+
(Writing) and [Zhang Yi Jiang][4] (Design).
18+
19+
## Contributors
20+
21+
- [Caio Romão][5] (Spelling corrections)
22+
- [Andreas Blixt][6] (Language corrections)
23+
24+
## Hosting
1525

26+
JavaScript Garden is hosted on GitHub, but [Cramer Development][7] supports us
27+
with a mirror at [JavaScriptGarden.info][8].
28+
29+
## License
30+
31+
JavaScript Garden is published under the [MIT license][9] and hosted on
32+
[GitHub][10]. If you find errors or typos please [file an issue][11] or a pull
33+
request on the repository. You can also find us in the [JavaScript room][12] on
34+
Stack Overflow chat.
35+
36+
[1]: https://developer.mozilla.org/en/JavaScript/Guide
37+
[2]: http://stackoverflow.com/
38+
[3]: http://stackoverflow.com/users/170224/ivo-wetzel
39+
[4]: http://stackoverflow.com/users/313758/yi-jiang
40+
[5]: https://github.com/caio
41+
[6]: https://github.com/blixt
42+
[7]: http://cramerdev.com/
43+
[8]: http://javascriptgarden.info/
44+
[9]: https://github.com/BonsaiDen/JavaScript-Garden/blob/next/LICENSE
45+
[10]: https://github.com/BonsaiDen/JavaScript-Garden
46+
[11]: https://github.com/BonsaiDen/JavaScript-Garden/issues
47+
[12]: http://chat.stackoverflow.com/rooms/17/javascript

doc/en/intro/license.md

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

doc/fi/array/constructor.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## `Array`-konstruktori
2+
3+
`Array`-oletuskonstruktorin käytös ei ole lainkaan yksiselitteistä. Tämän vuoksi suositellaankin, että konstruktorin sijasta käytetään literaalinotaatiota `[]`.
4+
5+
[1, 2, 3]; // Tulos: [1, 2, 3]
6+
new Array(1, 2, 3); // Tulos: [1, 2, 3]
7+
8+
[3]; // Tulos: [3]
9+
new Array(3); // Tulos: []
10+
new Array('3') // Tulos: ['3']
11+
12+
Mikäli `Array`-konstruktorille annetaan vain yksi argumentti ja se on tyypiltään `Number`, konstruktori palauttaa uuden *harvan* taulukon, jonka `length`-attribuutti on asetettu annetun numeron mukaisesti. On tärkeää huomata, että **ainoastaan** `length` asetetaan tällä tavoin, todellisia taulukon indeksejä ei alusteta.
13+
14+
var arr = new Array(3);
15+
arr[1]; // undefined
16+
1 in arr; // false, indeksiä ei ole alustettu
17+
18+
Tämä on käytännöllistä vain harvoin, kuten merkkijonon toiston tapauksessa. Tällöin voidaan välttää `for-luupin` käyttämistä.
19+
20+
new Array(count + 1).join(stringToRepeat);
21+
22+
### Yhteenveto
23+
24+
`Array`-konstruktorin käyttöä tulee käyttää niin paljon kuin suinkin mahdollista. Sen sijaan on suositeltavaa käyttää literaalinotaatiota. Literaalit ovat lyhyempiä ja niiden syntaksi on selkeämpi. Tämän lisäksi ne tekevät koodista luettavampaa.
25+

doc/fi/array/general.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
## Taulukon iterointi ja attribuutit
2+
3+
Vaikka taulukot ovatkin JavaScript-olioita, niiden tapauksessa ei välttämättä kannata käyttää [`for in loop`](#object.forinloop)-luuppia. Pikemminkin tätä tapaa tulee **välttää**.
4+
5+
> **Huomio:** JavaScript-taulukot **eivät ole** *assosiatiivisia*. JavaScriptissa ainoastaan [oliot](#object.general) ovat avain-arvo-mappauksia. On huomattavaa, että toisin kuin assosiatiiviset taulukot, oliot **eivät** säilytä järjestystään.
6+
7+
`for in`-luuppi iteroi kaikki prototyyppiketjun sisältämät ominaisuudet. Tämän vuoksi tulee käyttää erityistä [`hasOwnProperty`](#object.hasownproperty)-metodia, jonka avulla voidaan taata, että käsitellään oikeita ominaisuuksia. Tästä johtuen iteroint on jo lähtökohtaisesti jopa **kaksikymmentä** kertaa hitaampaa kuin normaalin `for`-luupin tapauksessa.
8+
9+
### Iterointi
10+
11+
Taulukkojen tapauksessa paras suorituskyky voidaan saavuttaa käyttämällä klassista `for`-luuppia.
12+
13+
var list = [1, 2, 3, 4, 5, ...... 100000000];
14+
for(var i = 0, l = list.length; i < l; i++) {
15+
console.log(list[i]);
16+
}
17+
18+
Edelliseen esimerkkiin liittyy yksi mutta. Listan pituus on tallennettu välimuistiin erikseen käyttämällä `l = list.length`-lauseketta.
19+
20+
Vaikka `length`-ominaisuus määritelläänkin taulukossa itsessään, arvon hakeminen sisältää ylimääräisen operaation. Uudehkot JavaScript-ympäristöt **saattavat** optimoida tämän tapauksen. Tästä ei kuitenkaan ole mitään takeita.
21+
22+
Todellisuudessa välimuistin käytön pois jättäminen voi hidastaa luuppia jopa puolella.
23+
24+
### `length`-ominaisuus
25+
26+
`length`-ominaisuuden *getteri* palauttaa yksinkertaisesti taulukon sisältämien alkioiden määrän. Sen *setteriä* voidaan käyttää taulukon **typistämiseen**.
27+
28+
var foo = [1, 2, 3, 4, 5, 6];
29+
foo.length = 3;
30+
foo; // [1, 2, 3]
31+
32+
foo.length = 6;
33+
foo; // [1, 2, 3]
34+
35+
Pituuden pienemmäksi asettaminen typistää taulukkoa. Sen kasvattaminen ei kuitenkaan vaikuta mitenkään.
36+
37+
### Yhteenveto
38+
39+
Parhaan suorituskyvyn kannalta on parhainta käyttää tavallista `for`-luuppia ja tallentaa `length`-ominaisuus välimuistiin. `for in`-luupin käyttö taulukon tapauksessa on merkki huonosti kirjoitetusta koodista, joka on altis bugeille ja heikolle suorituskyvylle.
40+

0 commit comments

Comments
 (0)