Skip to content

Instantly share code, notes, and snippets.

@pedromcunha
Created August 2, 2014 17:36
Show Gist options
  • Save pedromcunha/b03261b10089a11abc3e to your computer and use it in GitHub Desktop.
Save pedromcunha/b03261b10089a11abc3e to your computer and use it in GitHub Desktop.
OOP JavaScript: Adding or removing objects via built in functions.
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