call method in javascript !!
Anonymous
// using call to chain constructor
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
function Toy(name, price) {
Product.call(this, name, price);
this.category = 'toy';
}
var cheese = new Food('feta', 5);
var fun = new Toy('robot', 40);
// code is working fine ,but one thing I am unable to understand that if we omit this from the line Product.call(this, name, price) to Product.call(name, price) then also same output is coming so I was thinking what is need to write this then in above call