OOP 정리
console.log("this is this");
let cat = {
animal: "cat",
first: 0.5,
second: 1.7,
sum: function () {
return this.first + this.second;
},
};
console.log("cat.sum() :", cat.sum(), "kg");
console.log("constructor");
function Cat(name, age, first, second) {
this.name = name;
this.age = age;
this.first = first;
this.second = second;
}
let koi = new Cat("koi", 0.5, 0.6, 1.7);
let honeybread = new Cat("honeybread", 3, 2.5, 3.4);
Cat.prototype.sum = function () {
return "prototype :" + (this.first + this.second);
};
let coco = new Cat("coco", 2, 0.4, 5);
coco.sum = function () {
return "this :" + (this.first + this.second);
};
let mandoo = new Cat("mandoo", 2, 1.3, 2);
console.log("coco.sum()", coco.sum());
console.log("mandoo.sum()", mandoo.sum());