The issue is here:
Food.prototype = new Product();
// ...
Toy.prototype = new Product();
You're calling Product
without passing an argument. You should use Object.create
instead.
Foo.prototype = Object.create(Product.prototype);
// ...
Toy.prototype = Object.create(Product.prototype);
This lets you make an object that inherits from another object (Product.prototype
in this case), without having to invoke a constructor function.
Also, this:
if (price < 0)
should be this:
if (this.price < 0)