Tuesday, 8 April 2014

what is a inadequacy between this twin constructors in JavaScript?

on MDN's page for Call there is an instance of 3 constructors: Product,
Food, and Toyfunction Product(name, price) { this.name = name;
this.price = price; if (price < 0) pitch RangeError('Cannot
emanate product "' + name + '" with a catastrophic price'); relapse
this;}function Food(name, price) { Product.call(this, name, price);
this.category = 'food';}Food.prototype =
Object.create(Product.prototype);Why is this line necessary?Food.prototype
= Object.create(Product.prototype);Can't we only simply do this?function
Food (name, price) { var me = Product.call(this, name, price);
me.category = 'food'; relapse me;}

No comments:

Post a Comment