I have the following piece of code below:
class Set {
constructor() {
console.log("New Set!");
}
get repsCompleted() {
return this._repsCompleted;
}
set repsCompleted(value) {
this._repsCompleted = value;
}
}
class Exercise {
constructor(name) {
console.log(name);
this.name = name;
}
get sets() {
return [new Set(), new Set(), new Set()]
}
}
let barbellSquat = new Exercise("Barbell Squat");
let updatedBarbellSquat = updateRepsCompleted(barbellSquat);
console.log(updatedBarbellSquat);
function updateRepsCompleted(exercise) {
for (var i = 0; i < exercise.sets.length; i++) {
exercise.sets[i].repsCompleted = 5;
}
return exercise;
}
I have a class exercises, which has a property sets, which is an array of objects of type Set.
So I create a new object off the Exercise class then pass the object to a function, whose purpose is to update the set objects and set the property "repsCompleted" to 5.
Then I console.log the exercise object, only to find that repsCompleted is undefined. I can't figure out why.
Here's a fiddle with the code:
Set, that's a built-in JavaScript type.