2020/Vanilla JavaScript
Javascript #prototype
꽃꽂이하는개발자
2020. 3. 28. 21:47
반응형
function Animal(type, name, sound) {
this.type = type;
this.name = name;
this.sound = sound;
}
const dog = new Animal("개", "멍멍이", "멍멍");
const cat = new Animal("고양이", "야옹이", "야옹");
Animal.prototype.say = function() {
console.log(this.sound);
};
dog.say();
cat.say();
반응형