Skip to content

Commit 860f7c2

Browse files
committed
translate "Closures Inside Loops" in "Function" to ja
1 parent ae60364 commit 860f7c2

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎doc/ja/function/closures.md‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,21 @@ JavaScriptでは、スコープ自体を参照・代入する事が出来無い
3434

3535
上記のコードは`Counter`のスコープ中にある変数`count`の値を変更する事は**ありません**。`foo.hack`は**その**スコープで定義されていないからです。これは*グローバル*変数`count`の作成 -またはオーバーライド- の代わりになるでしょう。
3636

37-
### Closures Inside Loops
37+
### ループ中のクロージャ
3838

39-
One often made mistake is to use closures inside of loops, as if they were
40-
copying the value of the loops index variable.
39+
一つ良くある間違いとして、ループのインデックス変数をコピーしようとしてか、ループの中でクロージャを使用してしまうというものがあります。
4140

4241
for(var i = 0; i < 10; i++) {
4342
setTimeout(function() {
44-
console.log(i);
43+
console.log(i);
4544
}, 1000);
4645
}
4746

48-
The above will **not** output the numbers `0` through `9`, but will simply print
49-
the number `10` ten times.
47+
上記の例では`0`から`9`の数値が出力される事は**ありません**。もっと簡単に`10`という数字が10回出力されるだけです。
5048

51-
The *anonymous* function keeps a **reference** to `i` and at the time
52-
`console.log` gets called, the `for loop` has already finished and the value of
53-
`i` as been set to `10`.
49+
**匿名**関数は`i`への**参照**を維持しており、同時に`forループ`は既に`i`の値に`10`をセットし終った`console.log`が呼ばれてしまいます。
5450

55-
In order to get the desired behavior, it is necessary to create a **copy** of
56-
the value of `i`.
51+
期待した動作をする為には、`i`の値の**コピー**を作る必要があります。
5752

5853
### Avoiding the Reference Problem
5954

0 commit comments

Comments
 (0)