ch02#side-effects
createCart = function (items) {
var cart = Object.create(cartProto);
cart.items = items;
return cart;
}
"At this point, cart.items is a reference to the prototype items attribute.”
I’m not sure that this is true. I think it is a shared reference to the array ["apple", "pear", "orange"]. cartProto.items should remain an empty array.
I believe that cart.items = items; in createCart masks cartProto.items each time.
Also, it is stated:
cart.items = Object.create(items);
Now the new cart will have its own copy of the item data, so changes will not be de‐
structive to storedCart.
I believe the new cart's items property will be a new empty object with prototypally inherits from the array ["apple", "pear", "orange"] rather than a copy, which could be obtain using cart.items = items.slice();.
ch02#side-effects
I’m not sure that this is true. I think it is a shared reference to the array
["apple", "pear", "orange"].cartProto.itemsshould remain an empty array.I believe that
cart.items = items;increateCartmaskscartProto.itemseach time.Also, it is stated:
cart.items = Object.create(items);I believe the new cart's items property will be a new empty object with prototypally inherits from the array
["apple", "pear", "orange"]rather than a copy, which could be obtain usingcart.items = items.slice();.