I have an idea about Backbone with these two attributes:
var MyBasketView = Backbone.View.extend({
_totalCost: 0,
_devices: [],
and upon initialization, I scan the array in localStorage with several devices, which I pop them into the _devices array and sum them up total with _totalCost like this
var self = this;
_.each(this._cartItems, function(cartItem) {
self._totalCost += cartItem.item.cost;
self._devices.push(cartItem.item);
}
In my router, I delete this view when I leave this page, and again create this view when I return. The problem is that when I print the attributes in my initialization function, the total cost is 0, and the device array still has the devices before.
Should it be reset when I delete the view or create it using the new MyBasketView ()?
, , , , , ?