Skip to content

Commit 491468c

Browse files
committed
Final pass done.
1 parent 9d94790 commit 491468c

File tree

9 files changed

+239
-409
lines changed

9 files changed

+239
-409
lines changed

doc/fi/object/forinloop.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
1-
## The `for in` Loop
1+
## `for in`-luuppi
22

3-
Just like the `in` operator, the `for in` loop also traverses the prototype
4-
chain when iterating over the properties of an object.
3+
Aivan kuten `in`-operaattori, myös `for in`-luuppi käy olion prototyyppiketjun läpi iteroidessaan sen ominaisuuksia.
54

6-
> **Note:** The `for in` loop will **not** iterate over any properties that
7-
> have their `enumerable` attribute set to `false`; for example, the `length`
8-
> property of an array.
9-
10-
// Poisoning Object.prototype
5+
> **Huomio:** `for in`-luuppi **ei** iteroi ominaisuuksia, joiden `enumerable`-attribuutti on asetettu arvoon `false`. Eräs esimerkki tästä on taulukon `length`-ominaisuus.
6+
7+
// Object.prototypen myrkyttäminen
118
Object.prototype.bar = 1;
129

1310
var foo = {moo: 2};
1411
for(var i in foo) {
15-
console.log(i); // prints both bar and moo
12+
console.log(i); // tulostaa sekä bar että moo
1613
}
1714

18-
Since it is not possible to change the behavior of the `for in` loop itself, it
19-
is necessary to filter out the unwanted properties inside the loop body ,
20-
this is done by using the [`hasOwnProperty`](#object.hasownproperty) method of
21-
`Object.prototype`.
15+
Koska `for in`-luupin käytöstapaa ei voida muokata suoraan, tulee ei-halutut ominaisuudet karsia itse luupin sisällä. Tämä on mahdollista käyttäen `Object.prototype`-olion [`hasOwnProperty`](#object.hasownproperty)-metodia.
2216

23-
> **Note:** Since the `for in` always traverses the complete prototype chain, it
24-
> will get slower with each additional layer of inheritance added to an object.
17+
> **Huomio:** `for in`-luupin suorittaminen hidastuu sitä enemmän, mitä pidempi olion prototyyppiketju on. Tämä johtuu siitä, että se joutuu käymään koko ketjun sisällön läpi.
2518
26-
### Using `hasOwnProperty` for Filtering
19+
### `hasOwnProperty`-metodin käyttäminen karsimiseen
2720

28-
// still the foo from above
21+
// foo kuten yllä
2922
for(var i in foo) {
3023
if (foo.hasOwnProperty(i)) {
3124
console.log(i);
3225
}
3326
}
3427

35-
This version is the only correct one to use. Due to the use of `hasOwnProperty` it
36-
will **only** print out `moo`. When `hasOwnProperty` is left out, the code is
37-
prone to errors in cases where the native prototypes - e.g. `Object.prototype` -
38-
have been extended.
28+
Tämä versio on ainut oikea. Se tulostaa **ainoastaan** `moo`, koska se käyttää `hasOwnProperty`-metodia oikein. Kun se jätetään pois, on koodi altis virheille tapauksissa, joissa prototyyppejä, kuten `Object.prototype`, on laajennettu.
3929

40-
One widely used framework which does this is [Prototype][1]. When this
41-
framework is included, `for in` loops that do not use `hasOwnProperty` are
42-
guaranteed to break.
30+
[Prototype][1] on eräs yleisesti käytetty ohjelmointialusta, joka tekee näin. Kun kyseistä alustaa käytetään, `for in`-luupit, jotka eivät käytä `hasOwnProperty`-metodia, menevät varmasti rikki.
4331

44-
### In Conclusion
32+
### Yhteenveto
4533

46-
It is recommended to **always** use `hasOwnProperty`. Never should any
47-
assumptions be made about the environment the code is running in, or whether the
48-
native prototypes have been extended or not.
34+
On suositeltavaa käyttää **aina** `hasOwnProperty`-metodia. Ei ole kannattavaa tehdä ajoympäristöön tai prototyyppeihin liittyviä oletuksia.
4935

5036
[1]: http://www.prototypejs.org/
5137

doc/fi/object/general.md

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
## Object Usage and Properties
1+
## Olioiden käyttö ja ominaisuudet
22

3-
Everything in JavaScript acts like an object, with the only two exceptions being
4-
[`null`](#core.undefined) and [`undefined`](#core.undefined).
3+
Kaikki muuttujat, kahta poikkeusta lukuunottamatta, käyttäytyvät JavaScriptissä kuten olio. Nämä poikkeukset ovat [`null`](#core.undefined) sekä [`undefined`](#core.undefined).
54

65
false.toString() // 'false'
76
[1, 2, 3].toString(); // '1,2,3'
@@ -10,38 +9,31 @@ Everything in JavaScript acts like an object, with the only two exceptions being
109
Foo.bar = 1;
1110
Foo.bar; // 1
1211

13-
A common misconception is that number literals cannot be used as
14-
objects. That is because a flaw in JavaScript's parser tries to parse the *dot
15-
notation* on a number as a floating point literal.
12+
Yleisesti luullaan ettei numeroliteraaleja voida käyttää olioina. Tämä johtuu viasta JavaScriptin parserissa. Se yrittää parsia numeron *pistenotaatiota* liukulukuliteraalina.
1613

17-
2.toString(); // raises SyntaxError
14+
2.toString(); // palauttaa SyntaxError-virheen
1815

19-
There are a couple of workarounds which can be used in order make number
20-
literals act as objects too.
16+
Tämä voidaan välttää esimerkiksi seuraavasti.
2117

22-
2..toString(); // the second point is correctly recognized
23-
2 .toString(); // note the space left to the dot
24-
(2).toString(); // 2 is evaluated first
18+
2..toString(); // toinen piste tunnistuu oikein
19+
2 .toString(); // huomaa pisteen vasemmalla puolen oleva väli
20+
(2).toString(); // 2 arvioidaan ensi
2521

26-
### Objects as a Data Type
22+
### Oliot tietotyyppinä
2723

28-
Objects in JavaScript can also be used as a [*Hashmap*][1], they mainly consist
29-
of named properties mapping to values.
24+
JavaScriptin olioita voidaan käyttää myös [*hajautustauluna*][1], koska ne muodostavat pääasiassa avaimien ja niihin liittyvien arvojen välisen mappauksen.
3025

31-
Using a object literal - `{}` notation - it is possible to create a
32-
plain object. This new object [inherits](#object.prototype) from `Object.prototype` and
33-
has no [own properties](#object.hasownproperty) defined on it.
26+
Olioliteraalinotaatiota - `{}` - käyttäen voidaan luoda tyhjä olio. Tämä olio [perii](#object.prototype) `Object.prototype`-olion eikä sille ole määritelty [omia ominaisuuksia](#object.hasownproperty).
3427

35-
var foo = {}; // a new empty object
28+
var foo = {}; // uusi, tyhjä olio
3629

37-
// a new object with a property called 'test' with value 12
30+
// uusi, tyhjä olio, joka sisältää ominaisuuden 'test' arvolla 12
3831
var bar = {test: 12};
3932

40-
### Accessing Properties
33+
### Pääsy ominaisuuksiin
34+
35+
Olion ominaisuuksiin voidaan päästä käsiksi kahta eri tapaa käyttäen. Siihen voidaan käyttää joko piste- tai hakasulkunotaatiota.
4136

42-
The properties of an object can be accessed in two ways, via either the dot
43-
notation, or the square bracket notation.
44-
4537
var foo = {name: 'Kitten'}
4638
foo.name; // kitten
4739
foo['name']; // kitten
@@ -50,17 +42,13 @@ notation, or the square bracket notation.
5042
foo[get]; // kitten
5143

5244
foo.1234; // SyntaxError
53-
foo['1234']; // works
45+
foo['1234']; // toimii
5446

55-
Both notations are identical in their workings, with the only difference being that
56-
the square bracket notation allows for dynamic setting of properties, as well as
57-
the use of property names that would otherwise lead to a syntax error.
47+
Kumpikin notaatio toimii samalla tavoin. Ainut ero liittyy siihen, että hakasulkunotaation avulla ominaisuuksien arvoja voidaan asettaa dynaamisesti. Se sallii myös muuten hankalien, virheeseen johtavien nimien käyttämisen.
5848

59-
### Deleting Properties
49+
### Ominaisuuksien poistaminen
6050

61-
The only way to actually remove a property from an object is to use the `delete`
62-
operator; setting the property to `undefined` or `null` only remove the
63-
*value* associated with the property, but not the *key*.
51+
Ainut tapa poistaa olion ominaisuus on käyttää `delete`-operaattoria. Ominaisuuden asettaminen joko arvoon `undefined` tai `null` poistaa vain siihen liittyneen arvon muttei itse *avainta*.
6452

6553
var obj = {
6654
bar: 1,
@@ -77,23 +65,18 @@ operator; setting the property to `undefined` or `null` only remove the
7765
}
7866
}
7967

80-
The above outputs both `bar undefined` and `foo null` - only `baz` was
81-
removed and is therefore missing from the output.
68+
Yllä oleva koodi tulostaa sekä `both undefined` että `foo null`. Ainoastaan `baz` on poistettu. Täten sitä ei myöskään näy tulosteessa.
8269

83-
### Notation of Keys
70+
### Avainnotaatio
8471

8572
var test = {
86-
'case': 'I am a keyword so I must be notated as a string',
87-
delete: 'I am a keyword too so me' // raises SyntaxError
73+
'case': 'Olen avainsana, joten minun tulee olla merkkijono',
74+
delete: 'Myös minä olen avainsana' // palauttaa SyntaxError-virheen
8875
};
8976

90-
Object properties can be both notated as plain characters and as strings. Due to
91-
another mis-design in JavaScript's parser, the above will throw
92-
a `SyntaxError` prior to ECMAScript 5.
77+
Olioiden ominaisuuksia voidaan notatoida käyttäen joko pelkkiä merkkejä tai merkkijonoja. Toisesta JavaScriptin suunnitteluvirheestä johtuen yllä oleva koodi palauttaa `SyntaxError`-virheen ECMAScript 5:ttä edeltävissä versioissa.
9378

94-
This error arises from the fact that `delete` is a *keyword*; therefore, it must be
95-
notated as a *string literal* to ensure that it will be correctly interpreted by
96-
older JavaScript engines.
79+
Tämä virhe johtuu siitä, että `delete` on *avainsana*. Täten se tulee notatoida *merkkijonona*. Tällöin myös vanhemmat JavaScript-tulkit ymmärtävät sen oikein.
9780

9881
[1]: http://en.wikipedia.org/wiki/Hashmap
9982

doc/fi/object/hasownproperty.md

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
## `hasOwnProperty`
22

3-
In order to check whether a object has a property defined on *itself* and **not**
4-
somewhere on its [prototype chain](#object.prototype), it is necessary to use the
5-
`hasOwnProperty` method which all objects inherit from `Object.prototype`.
3+
Jotta voimme tarkistaa onko olion ominaisuus määritelty siinä *itsessään*, tulee käyttää erityistä `Object.prototype`-oliosta periytyvää `hasOwnProperty`-metodia. Tällä tavoin vältämme [prototyyppiketjun](#object.prototype) sisältämät ominaisuudet.
64

7-
> **Note:** It is **not** enough to check whether a property is `undefined`. The
8-
> property might very well exist, but its value just happens to be set to
9-
> `undefined`.
5+
> **Huomio:** **Ei** riitä tarkistaa vain että ominaisuuden arvo on `undefined`. Ominaisuus voi hyvinkin olla olemassa. Sen arvoksi on vain satuttu asettamaan `undefined`.
106
11-
`hasOwnProperty` is the only thing in JavaScript which deals with properties and
12-
does **not** traverse the prototype chain.
7+
`hasOwnProperty` on ainut JavaScriptin sisältämä metodi, joka käsittelee ominaisuuksia **eikä** käy prototyyppiketjun sisältöä läpi.
138

14-
// Poisoning Object.prototype
9+
// Object.prototypen myrkyttäminen
1510
Object.prototype.bar = 1;
1611
var foo = {goo: undefined};
1712

@@ -21,33 +16,26 @@ does **not** traverse the prototype chain.
2116
foo.hasOwnProperty('bar'); // false
2217
foo.hasOwnProperty('goo'); // true
2318

24-
Only `hasOwnProperty` will give the correct and expected result, this is
25-
essential when iterating over the properties of any object. There is **no** other
26-
way to exclude properties that are not defined on the object *itself*, but
27-
somewhere on its prototype chain.
19+
Ainoastaan `hasOwnProperty` palauttaa oikean ja odotetun tuloksen. Sen tietäminen on olennaista minkä tahansa olion ominaisuuksia iteroidessa. Tämä on **ainut** tapa löytää olion itsensä ominaisuudet prototyyppiketjusta riippumatta.
2820

29-
### `hasOwnProperty` as a Property
21+
### `hasOwnProperty` ominaisuutena
3022

31-
JavaScript does **not** protect the property name `hasOwnProperty`; thus, if the
32-
possibility exists that an object might have a property with this name, it is
33-
necessary to use an *external* `hasOwnProperty` in order to get correct results.
23+
JavaScript **ei** suojele `hasOwnProperty`-metodin nimeä. Täten on mahdollista, että olio voi sisältää samannimisen ominaisuuden. Jotta voimme saada oikeita tuloksia, tulee sen sijaan käyttää *ulkoista* `hasOwnProperty`-metodia.
3424

3525
var foo = {
3626
hasOwnProperty: function() {
3727
return false;
3828
},
39-
bar: 'Here be dragons'
29+
bar: 'Olkoon vaikka lohikäärmeitä'
4030
};
4131

42-
foo.hasOwnProperty('bar'); // always returns false
32+
foo.hasOwnProperty('bar'); // palauttaa aina false
4333

44-
// Use another Object's hasOwnProperty and call it with 'this' set to foo
34+
// Käytä toisen olion hasOwnProperty-metodia ja kutsu sitä asettamalla
35+
// 'this' foohon
4536
({}).hasOwnProperty.call(foo, 'bar'); // true
4637

47-
### In Conclusion
38+
### Yhteenveto
4839

49-
When checking for the existence of a property on a object, `hasOwnProperty` is
50-
the **only** method of doing so. It is also recommended to make `hasOwnProperty`
51-
part of **every** [`for in` loop](#object.forinloop), this will avoid errors from
52-
extended native [prototypes](#object.prototype).
40+
Mikäli pitää selvittää kuuluuko ominaisuus olioon vai ei, **ainoastaan** `hasOwnProperty` voi kertoa sen. Tämän lisäksi on suositeltavaa käyttää `hasOwnProperty`-metodia osana **jokaista** [`for in`-luuppia](#object.forinloop). Tällä tavoin voidaan välttää natiivien [prototyyppien](#object.prototype) laajentamiseen liittyviä ongelmia.
5341

0 commit comments

Comments
 (0)