Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created July 31, 2014 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotaroito/03fd767e28274cdc5226 to your computer and use it in GitHub Desktop.
Save kotaroito/03fd767e28274cdc5226 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var Cart = (function(){
var items = [];
return {
add: function(item) {
items.push(item);
},
remove: function(item) {
var index = items.indexOf(item);
if (index > -1)
items.splice(index, 1);
},
show: function() {
items.forEach(function(item){
console.log(item);
});
console.log("--------------------");
}
};
})();
Cart.add("apple");
Cart.add("grape");
Cart.add("peach");
Cart.show();
Cart.remove("grape");
Cart.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment