어케할까?
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()으로 넣는다.
댓글 영역