im creating in JS a Cart, whitch takes pizzas or salads, or another food products, then i save the cart in localStorage with JSON.stringify. But when i retrieve the cart from JSON.parse, the items are simple Objects, whereas before it was an instance of Pizza, or Salad...etc
The items before:
[Pizza]: {id: 1, name:"Hawaï pizza", ...}
[Pizza]: {id: 2, name:"Fresh Italian pizza", ...}
[Salad]: {id: 3, name:"Chicken Salad", ...}
The items after:
0: {id: 1, name:"Hawaï pizza", ...}
1: {id: 2, name:"Fresh Italian pizza", ...}
2: {id: 3, name:"Chicken Salad", ...}
The problem: I have implemented some methods on each products (like Pizza.getSize() ...etc) that doesnt work after JSON.parse.
How can I retrieve that items with their original Prototypes ? Or is here a trick used to resolve that ?
Thanks