📜  什么是 fn.call - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:44.395000             🧑  作者: Mango

代码示例2
function Product(name, price) {
  this.name = name;
  this.price = price;
}

function Food(name, price) {
  Product.call(this, name, price);
  this.category = 'food';
}

function Toy(name, price) {
  Product.call(this, name, price);
  this.category = 'toy';
}

const cheese = new Food('feta', 5);
const fun = new Toy('robot', 40);