//этот код менять нельзя function Cart () { } Cart.prototype.add = function (item) { if (!this.goods) { this.goods = []; } this.goods.push(item); //добавляет товар в корзину }; //редактируемый код function UserCart () { } function Item (idNum, item, sum) { this.idNum = idNum; this.item = item; this.sum = sum; } UserCart.prototype = Object.create(Cart.prototype); const cart = new UserCart(); const item = new Item("1", 'Сhair', "20$"); cart.add(); console.log(cart.goods); |
2 answers
Add output to the console in the Cart.prototype.add method, like this:
Cart.prototype.add = function (item) { if (!this.goods) { this.goods = []; } this.goods.push(item); //добавляет товар в корзину console.log('В корзине %s товаров', this.goods.length) }; And look at the output
- Did not quite understand the question, please specify. - Alexey Matveev
- Eugene, reading the code in this format is very difficult. Please post your code on jsfiddle.net. Give here a link - Alexey Matveev
|
cart.add (item);
cart.add(item); Complete code:
//этот код менять нельзя function Cart () { } Cart.prototype.add = function (item) { if (!this.goods) { this.goods = []; } this.goods.push(item); //добавляет товар в корзину }; //редактируемый код function UserCart () { } function Item (idNum, item, sum) { this.idNum = idNum; this.item = item; this.sum = sum; } UserCart.prototype = Object.create(Cart.prototype); const cart = new UserCart(); const item = new Item("1", 'Сhair', "20$"); cart.add(item); console.log(cart.goods); |
return item, will return something - splash58cart.add(item); console.log(cart.goods);- so you will see what worked - splash58