Prototype
const car = {
wheels: 4,
drive(){
console.log('drive..');
},
}
const bmw = {
color: 'red',
navagation: 1,
};
const benz = {
color: 'black'
};
const audi = {
color: 'blue'
};
bmw.__proto__ = car;
benz.__proto__ = car;
audi.__proto__ = car;
const x5 = {
color: "white",
name: "x5",
};
x5.__proto__ = bmw;
생성자함수
const Bmw = function(color){
this.color = color;
};
Bmw.prototype = {
constructor: Bmw,
wheels: 4,
drive() {
console.log("drive..");
},
navigation: 1,
stop() {
console.log("STOP!");
},
};
const x5 = new Bmw("red");
const z4 = new Bmw("blue");
const Bmw = function(color){
const c = color;
this.getColor = function(){
console.log(c);
};
};
const x5 = new Bmw("red");