Skip to content

Instantly share code, notes, and snippets.

@srconklin
Created July 14, 2013 01:03
Show Gist options
  • Save srconklin/5992780 to your computer and use it in GitHub Desktop.
Save srconklin/5992780 to your computer and use it in GitHub Desktop.
Untitled
function Product(name, price) {
this.name = name;
this.price = price;
if (price < 0)
throw RangeError('Cannot create product "' + name + '" with a negative price');
return this;
}
Product.prototype.sayprice = function() {
return "the price is :" + this.price
};
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
Food.prototype = new Product();
function Toy(name, price) {
Product.call(this, name, price);
this.category = 'toy';
}
Toy.prototype = new Product();
var cheese = new Food('feta', 5);
var fun = new Toy('robot', 40);
console.log(cheese);
console.log(cheese.sayprice());
{"view":"separate","fontsize":"70","seethrough":"","prefixfree":"1","page":"html"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment