Created
July 31, 2014 15:11
-
-
Save kotaroito/03fd767e28274cdc5226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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