๋ฐ์ํ
๐ค๋ด๋ถํจ์(Inner Function) : ํจ์ ๋ด๋ถ์ ์ ์ธ๋ ํจ์๋ก ์ ์ธ๋ ํจ์์์๋ง ํธ์ถ ๊ฐ๋ฅ
์ค์ต์ฝ๋๐ฉ๐ป
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaScript</title>
</head>
<body>
<script type="text/javascript">
//์์ 1)
function display() {
alert("display ํจ์์ ๋ช
๋ น ์คํ-1");
}
//๋์ผํ ์ด๋ฆ์ ํจ์ ์ ์ธ ๊ฐ๋ฅ - ๊ธฐ์กด ํจ์ ๋ฎ์ด์์ฐ๊ธฐ(OverWrite)
function display() {
alert("display ํจ์์ ๋ช
๋ น ์คํ-2");
}
display();//์ถ๋ ฅ ๊ฒฐ๊ณผ => "display ํจ์์ ๋ช
๋ น ์คํ-2"
//์์ 2)
function outer() {
alert("outer ํจ์์ ๋ช
๋ น ์คํ");
//๋ด๋ถํจ์ ์ ์ธ - ํจ์๊ฐ ์ข
๋ฃ๋๋ฉด ๋ด๋ถํจ์ ์๋ฉธ
function inner() {
alert("inner ํจ์์ ๋ช
๋ น ์คํ");
}
//๋ด๋ถํจ์๋ ์ ์ธ๋ ์ธ๋ถํจ์์์๋ง ํธ์ถ ๊ฐ๋ฅ(=์ธ๋ถํจ์ ํธ์ถ ์ํ๋ฉด ๋ด๋ถํจ์ ์ฌ์ฉ ๋ถ๊ฐ)
inner();
}
inner();//์๋ฌ๋ฐ์. ๋ด๋ถํจ์๋ง ํธ์ถ์ ๋ถ๊ฐ๋ฅ
outer();//ํธ์ถ ์, outer ํจ์ ๋ช
๋ น ์คํ๋๊ณ inner ํจ์ ๋ช
๋ น์ด ์ฐจ๋ก๋๋ก ์คํ๋จ
</script>
</body>
</html>
๋ฐ์ํ
'Frontend > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript]๋ด์ฅํจ์ - encodeURIComponent & decodeURIComponent (1) | 2024.01.04 |
---|---|
[JavaScript]๋ด์ฅํจ์ - setTimeout/setInterval/clearTimeout/clearInterval (0) | 2024.01.04 |
[JavaScript] return ๋ช ๋ น (0) | 2024.01.02 |
[JavaScript]ํจ์์ ์ธ์(Argument) (0) | 2024.01.02 |
[JavaScript]๋ณ์์ ์ ํจ๋ฒ์(Scope) (0) | 2023.12.29 |