I've encountered a problem with my program. I'm attempting to invoke a function that is part of an object stored in an array, but I'm having difficulty calling the function correctly.
//Initialize Array for Storing Projects
let allProjects = [];
//Define Parent Class for Creating Project Objects
class Project {
constructor(projTitle, projDescription, projHours, projReserved) {
//Declare variables
this._name = projTitle;
this._description = projDescription;
this._hours = projHours;
this._reserved = projReserved;
//Add newly created object to array
allProjects.push(this);
//TODO Reserve function
function reserve() {
if (this._reserved === false ) {
this._reserved === true;
} else {
console.log('The project you are trying to reserve has already been taken.');
}
}
};
}
//Invoke the reserve function of the object at index 0 in the array.
allProjects[0].reserve();
Upon running the program, I encounter the following error:
allProjects[0].reserve();
^
TypeError: allProjects[0].reserve is not a function
Any assistance or advice would be highly appreciated.