JSFiddle - React, Tailwind, and code Playground
by Stepan Suvorov
JavaScript
var myShop = function(){
var baskets = {};
var getBasket = function(id){
baskets[id] = baskets[id] || {item:[]};
return baskets[id]
}
return {
removeFromBasket: function(id, item){
var items = getBasket(id).items;
items.splice(items.indexOf(),1)
},
addToBasket: function(id, item){
getBAsket(id).items.push(item);
},
checkout: function(id){
// code to proceeed to checkout here
}
};
}
myShop.addToBasket(1000, {id: "pony", quantity: 1});
myShop.checkout(1000);