Node.json
[JavaScript] prototype
simstealer
2022. 9. 13. 12:34
// Prototype
// 객체내에 없는 맴버나 메소드를 Prototype이란 곳에서 한번 더 찾아사용하는 것.
// protoype 지정해보기(상속)
const car =
{
wheels: 4,
}
const audi =
{
color = "Black",
}
// car를 상속하여 audi에 wheels가 없지만 접근할 수 있게 해준다.
audi.__proto__ = car;
// 생성자를 이용하여 prototype 만들기
const Car = function (color)
{
this.color = color;
};
Car.prototype.wheels = 4;
const audi = new Car("Black");