@@ -76,48 +76,44 @@ JavaScriptは非同期なので、`setTimeout`と`setInterval`関数を使って
76
76
77
77
ここまでもまだ、任意の数字を与えられた為に影響を受けないタイムアウトがあるかもしれません。しかし、全てのタイムアウトのIDを追跡していく事は推奨されないので、それらは個別にクリアされます。
78
78
79
- ### Hidden use of ` eval `
79
+ ### 隠された ` eval ` の使用
80
80
81
- ` setTimeout ` and ` setInterval ` can also take a string as their first parameter.
82
- This feature should ** never** be used, since it internally makes use of ` eval ` .
81
+ ` setTimeout ` と` setInterval ` は、第一引数に文字列を取る事が可能です。この仕様は内部で` eval ` を使用する為に、** 絶対に** 使うべきではありません。
83
82
84
- > ** Note :** Since the timeout functions are ** not ** specified by the ECMAScript
85
- > standard, the exact workings when a string is passed to them might differ in
86
- > various JavaScript implementations. For example, Microsoft's JScript makes use of
87
- > the ` Function ` constructor in place of ` eval ` .
83
+ > ** 注意点 :** タイムアウト関数はECMAScript標準では制定されて ** いない ** 為に
84
+ > 文字列を引数にした場合に厳密な動作は色々なJavaScript実装により異なります。
85
+ > 例えば、MicrosoftのJScriptは ` eval ` の代わりに ` Function ` コンストラクターを
86
+ > 使用します。
88
87
89
88
function foo() {
90
- // will get called
89
+ // この先呼ばれる
91
90
}
92
91
93
92
function bar() {
94
93
function foo() {
95
- // never gets called
94
+ // 絶対に呼ばれない
96
95
}
97
96
setTimeout('foo()', 1000);
98
97
}
99
98
bar();
100
99
101
- Since ` eval ` is not getting called [ directly] ( #core.eval ) in this case, the string
102
- passed to ` setTimeout ` will get executed in the * global scope* ; thus, it will
103
- not use the local variable ` foo ` from the scope of ` bar ` .
100
+ この場合、` eval ` は[ 直接] ( #core.eval ) 呼ばれないので、文字列が渡された` setTimeout ` は* global scope* で実行されます。よって、` bar ` のスコープから` foo ` のローカル変数は使われないのです。
104
101
105
- It is further recommended to ** not** use a string for passing arguments to the
106
- function that will get called by either of the timeout functions.
102
+ さらに、文字列を関数に渡さ** ない** ように推奨される理由として、それぞれのタイムアウト関数から呼び出されるという事があります。
107
103
108
104
function foo(a, b, c) {}
109
105
110
- // NEVER use this
106
+ // 絶対にこのように使わない
111
107
setTimeout('foo(1,2, 3)', 1000)
112
108
113
- // Instead use an anonymous function
109
+ // 匿名関数を代わりに使用する
114
110
setTimeout(function() {
115
111
foo(a, b, c);
116
112
}, 1000)
117
113
118
- > ** Note :** While it is also possible to use the syntax
119
- > ` setTimeout(foo, 1000, a, b, c) ` , it is not recommended, as its use may lead
120
- > to subtle errors when used with [ methods ] ( #function.this ) .
114
+ > ** 注意点 :** ` setTimeout(foo, 1000, a, b, c) ` のようなシンタックスを使用する事も
115
+ > できますが、 [ メソッド ] ( #function.this ) を使用した際に、分かりにくいエラーが起りえるので
116
+ > 使用はお勧めしません。
121
117
122
118
### In Conclusion
123
119
0 commit comments