new를 붙이면 객체생성
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
console.log(new Food('cheese', 5).name);
붙이지 않으면 함수호출
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
return name;
}
console.log(Food('cheese', 5));
new를 사용하지 않고 call 사용
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
var food = {}
Food.call(food,'cheese', 5);
console.log(food.name);