상세 컨텐츠

본문 제목

[자바스크립트] function 안에 function을 넣는 두가지방법

카테고리 없음

by esoesmio 2023. 5. 23. 02:03

본문

어케할까?

 

 

 

 

 

function car(color, price,company){
    this.color = color;
    this.price = price;
    this.company = company;
    car.prototype.info = function (){
        console.log(`car 색상 : ${this.color}`);
        console.log(`car 가격 : ${this.price}`);
        console.log(`car 회사 : ${this.company}`);
    }
    // this.info =function (){
    //     console.log(`car 색상 : ${this.color}`);
    //     console.log(`car 가격 : ${this.price}`);
    //     console.log(`car 회사 : ${this.company}`);
    // }
}
car.prototype.info = function (){
    console.log(`car 색상 : ${this.color}`);
    console.log(`car 가격 : ${this.price}`);
    console.log(`car 회사 : ${this.company}`);
}
const kiacar = new car("red",30000000,"기아");
kiacar.info();
const hyundaicar = new car('black',6000000,"현대");
hyundaicar.info();
console.log(kiacar);
console.log(hyundaicar);

밖에서 프로토타입으로 넣거나 this.info = function()으로 넣는다.

댓글 영역