質問編集履歴
2
画像を挿入
test
CHANGED
File without changes
|
test
CHANGED
@@ -129,3 +129,19 @@
|
|
129
129
|
|
130
130
|
|
131
131
|
やっぱり返り値がよくわかりせん。
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
1.
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
![イメージ説明](60489a160742efe663e8e68c069b3fb1.png)
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
2.
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
![イメージ説明](57042bcd0859c8ac8fb3f17e7359d0c8.png)
|
1
ちょっとうまく伝えられていないので別の例を追記します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
下記例でいうならば、関数が実行、呼び出された
|
7
|
+
下記例でいうならば、関数が実行、呼び出された所に、処理結果が戻る、移動するので、下記例の場合sum(1,2);/に移動する。
|
8
8
|
|
9
9
|
つまり、var answerの中に入る。
|
10
10
|
|
@@ -39,3 +39,93 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
いつもすいませんがよろしくお願い致します。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
ちょっとうまく伝えられていないので別の例を追記します。
|
48
|
+
|
49
|
+
関数、引数の一連の処理。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```ここに言語を入力
|
54
|
+
|
55
|
+
function dispMsg(str){
|
56
|
+
|
57
|
+
document.write("<p>");2番目に実行、4番目に実行、5番目に実行
|
58
|
+
|
59
|
+
document.write(str);
|
60
|
+
|
61
|
+
document.write("</p>");
|
62
|
+
|
63
|
+
var result = str + ’girl’;
|
64
|
+
|
65
|
+
return result;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
1番目に実行dispMsg("Hello");関数の呼び出し1
|
74
|
+
|
75
|
+
3番目に実行 document.write("<p>Good morning</p>");関数の呼び出しではない
|
76
|
+
|
77
|
+
4番目に実行 dispMsg("bye");関数の呼び出し2
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
スクリプトは記述された順に上から下へ実行されていきますが、関数内に記述された処理は関数が呼び出されるまで実行されません。
|
84
|
+
|
85
|
+
つまりfunction dispMsgはいきなり実行されない。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
そして関数呼び出しが行われるといったん、function dispMsg に値が移動し、
|
90
|
+
|
91
|
+
function dispMsg 関数内の処理を実行した後で、
|
92
|
+
|
93
|
+
関数呼び出しの次の行(document.write("<p>Good morning</p>"); )へ再度処理が移ります。
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
引数Helloはfunction dispMsg 関数に渡され、
|
100
|
+
|
101
|
+
function dispMsg(’Hello ’)となる。
|
102
|
+
|
103
|
+
そして、 document.write(str);とdocument.write(str);の引数が同じなので、
|
104
|
+
|
105
|
+
(’Hello ’)は、document.write(str);に渡され、
|
106
|
+
|
107
|
+
document.write('Hellow');となり、
|
108
|
+
|
109
|
+
結果的に、HellowとPタグの 間に記載される。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
よって引数は同じ値名の所に渡されていくということになる。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
var result = str + ’girl’;
|
118
|
+
|
119
|
+
return result;
|
120
|
+
|
121
|
+
の部分は、
|
122
|
+
|
123
|
+
まずhellowgirlになってresult変数に渡される。
|
124
|
+
|
125
|
+
次にreturn hellowgirlとなり、
|
126
|
+
|
127
|
+
hellowgirlが返り値として、function dispMsgに渡されるのでしょうか?
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
やっぱり返り値がよくわかりせん。
|