Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

codingfarm

함수 정의 방법 4가지 본문

web/JavaScript

함수 정의 방법 4가지

scarecrow1992 2020. 10. 11. 17:15

1. function 키워드를 이용하는 방법

1
2
3
4
5
function hello(name){
    document.write(name+"님 환영합니다.");
    return 5;
}
var integer = hello("honggildong");
cs

 

2. 함수 리터럴을 이용하는 방법

1
2
3
4
var hello = function(name){
    document.write(name+"님 환영합니다.");
}
hello("ddandongne");
cs

 

3. Function 객체를 이용해서 정의하는 방법

1
2
var hello = new Function("name""document.write(name + '님 환영합니다.')");
hello("ddandongne");
cs

 

4. 익명 함수 확장을 이용해 정의하는 방법

1
2
3
(function(name){
    document.write(name+"님 환영합니다.");
})("ddandongne");
cs

 

 

 

 

'web > JavaScript' 카테고리의 다른 글

중첩 함수(Nested Function)  (2) 2020.10.11
함수 종류  (0) 2020.10.11
함수 리터럴(function literal)과 익명 함수(anonymous function)  (0) 2020.10.11
경품추천기  (0) 2020.10.09
소개  (0) 2020.10.09
Comments