var aquarium = {
Nemo : { type: "fish", species: "clownfish", length: 3.7 },
Marlin: { type: "fish", species: "clownfish", length: 4.1 },
Dory: { type: "fish", species: "blue tang", length: 6.2 },
Peach: { type: "echinoderm", species: "starfish", length: 5.3 },
"Coral Castle" : { type: "environment", material: "coquina", moves: false },
"Dragon Statue" : { type: "environment", material: "plastic", moves: false },
// function inside object is a method
addCritter: function( name, type, species, length){
this[name] = {type: type, species: species, length: length};
},
// function inside object is a method
addToy: function( name, type, material, moves){
this[name] = {type: type, material: material, moves: moves};
}
};
aquarium.addCritter("Bubbles", "fish", "yellow tang", 5.6);
// methods can be declared outside of the object
aquarium.takeOut = function(name){
// take the name and add it to the returned object
this[name].name = name;
var temp = this[name];
delete this[name];
return temp;
}
var fishOutOfWater = aquarium.takeOut("Marlin");
console.log(fishOutOfWater);
console.log(aquarium);
Comments
There are currently no comments