Created
July 14, 2013 01:03
-
-
Save srconklin/5992780 to your computer and use it in GitHub Desktop.
Untitled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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