I need to create an object that holds properties of birds. I then need to be able to use object methods to add new values to this object, without the methods being inside the object. I've been able to output what I'm supposed to, BUT only with the object methods inside the object. I'm don't know how I can apply an object outside of the object, to the properties within the object?
function Bird(species, color, locations) {
let birdObject = { species : species,
color : color,
locations : locations,
getColor : function() {
return this.color;
},
setColor : function(newColor) {
this.color = newColor;
},
addLocation : function(newLocation) {
this.locations.push(newLocation);
},
getLocations : function() {
return this.locations;
}
}
return(birdObject);
}
const newBird = Bird('canary', 'red', ['newyork', 'spain'])
console.log(newBird)
console.log(newBird.getColor());
newBird.setColor('yellow');
console.log(newBird.getColor());
newBird.addLocation('france');
console.log(newBird.getLocations())