回答編集履歴
1
対策
test
CHANGED
@@ -1,3 +1,47 @@
|
|
1
1
|
target_pos関数の中でtarget_posにカラ配列を代入しているので
|
2
2
|
|
3
3
|
名前が競合して上書きされています
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# 対策
|
8
|
+
|
9
|
+
以下エラー発生
|
10
|
+
|
11
|
+
```javascript
|
12
|
+
|
13
|
+
test(1);
|
14
|
+
|
15
|
+
test(2);
|
16
|
+
|
17
|
+
function test(n){
|
18
|
+
|
19
|
+
test=null;
|
20
|
+
|
21
|
+
console.log(n);
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
競合する名称を、varでローカル変数として回避
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
|
35
|
+
test(1);
|
36
|
+
|
37
|
+
test(2);
|
38
|
+
|
39
|
+
function test(n){
|
40
|
+
|
41
|
+
var test=null;
|
42
|
+
|
43
|
+
console.log(n);
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|