JSFiddle - React, Tailwind, and code Playground
by lasha
JavaScript
function Product(name, price) {
this.name = name;
this.price = price;
if (price < 0)
throw RangeError('Cannot create product "' + name + '" with a negative price');
//console.log(this);
return this;
}
function Food(name, price) {
Product.apply(this, arguments);
this.category = 'food';
console.log(this);
}
Food.prototype = new Product();
function Toy(name, price) {
Product.apply(this, arguments);
this.category = 'toy';
console.log(this);
}
Toy.prototype = new Product();
var cheese = new Food('feta', 5);
var fun = new Toy('robot', 40);
var fun2 = new Toy('car', 30);
document.write("Name of Cheese: " + cheese.name + "<br />");
document.write("Price of Fun: " + fun.price + "<br />");
document.write("Category of Fun2: " + fun2.category);