-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
createCart = function (items) {
var cart = Object.create(cartProto);
cart.items = items;
return cart;
}"At this point,
cart.itemsis 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();.
Metadata
Metadata
Assignees
Labels
No labels