Created
August 2, 2014 17:36
-
-
Save pedromcunha/b03261b10089a11abc3e to your computer and use it in GitHub Desktop.
OOP JavaScript: Adding or removing objects via built in functions.
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 fridge = { | |
addItem: function(name, type, expirationDate, healthRating) { | |
this[name] = {type: type, expirationDate: expirationDate, healthRating: healthRating}; | |
}, | |
removeItem: function(name){ | |
var recentlyRemoved = delete this[name]; | |
} | |
}; | |
fridge.addItem("bannana", "fruit", "2 weeks", "100"); | |
fridge.addItem("steak", "meat", "1 weeks", "70"); | |
console.log(fridge); | |
fridge.removeItem("bannana"); | |
console.log(fridge); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment