함수 정리

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 선언적 함수
        function func1(){
            document.write("function1이 실행되었습니다.<br>");
        };

        func1();

        // 익명함수
        const func2 = function(){
            document.write("function2가 실행되었습니다.<br>");
        };
        
        func2();

        //매개변수가 있는 함수
        function func3(name){
            document.write(name+" 실행되었습니다.<br>");
        };

        func3("function3");

        // 리턴값(종료)이 있는 함수
        function func4(){
            const str = "function4가 실행되었습니다.<br>";
            return str;
        };
        
        document.write(func4());

        // 즉시실행 함수
        (function func5(){
            document.write("function5가 실행되었습니다.<br>");
        }());

        // 화살표
        func6 = () => {
            document.write("function6이 실행되었습니다.<br>");
        };
        
        func6();
        
        // 화살표(익명함수)
        const func7 = () => {
            document.write("function7이 실행되었습니다.<br>");
        };

        func7();

        // 화살표(매개변수)
        const func8 = (str) => {
            document.write(str+"이 실행되었습니다.<br>");
        };

        func8("function8");

        // 화살표 (리턴값)
        const func9 = () => {
            const str = "function9가 실행되었습니다.<br>"
            return str;
        };

        document.write(func9());

        // 객체 지향(생성자) 함수
        function func10(name, action){
            this.name = name;
            this.action = action;
            this.study = function(){
                document.write(this.name + "이 "+this.action+"되었습니다.<br>")
            }
        };
        
        const obj1 = new func10("function10", " 실행");
        obj1.study();

        // 프로트타입 메서드(=함수)
        function func11(name, action){
            this.name = name;
            this.action = action;
        };
        func11.prototype.study = function(){
            document.write(this.name + "이 "+this.action+"되었습니다.<br>");
        }
        const obj2 = new func11("function11", "실행")
        obj2.study();

        // 클래스
        class func12{
            constructor(name, action){
                this.name = name;
                this.action = action;
            }
            study(){
                document.write(this.name + "이 "+this.action+"되었습니다.<br>");
            }
        }
        
        const obj3 = new func12("function12", "실행");
        obj3.study();

    </script>
</body>
</html>

Last updated

Was this helpful?