Illie

JS. 객체리터럴 함수 본문

JAVASCRIPT/자바스크립트

JS. 객체리터럴 함수

(*ᴗ͈ˬᴗ͈)ꕤ*.゚ 2022. 4. 15. 10:48

{
    function func(num, name, job){
        this.num = num;
        this.name = name;
        this.job = job;
    }

    func.prototype = {
        result1 : function(){
                document.write(this.num + ".내 이름은 " + this.name + "이며, 직업은 " + this.job + "입니다.");
        },
        result2 : function(){
                document.write(this.num + ".내 이름은 " + this.name + "이며, 직업은 " + this.job + "입니다.");
        }

    }
    
    //인스턴스 생성
    const info1 = new func("1", "웹쓰", "웹퍼블리셔");
    const info2 = new func("2", "웹스토리보이", "프론트엔드개발자");

    info1.result1();
    info2.result2();
}

'JAVASCRIPT > 자바스크립트' 카테고리의 다른 글

JS. 클래스 상속  (0) 2022.04.15
JS. 클래스  (0) 2022.04.15
JS. 프로토타입 함수  (0) 2022.04.15
JS. forEach문으로 JSON 값 가져오기  (0) 2022.04.15
JS. encode / decode  (0) 2022.04.15
Comments