Using ES6 Classes
Visit http://weblogs.asp.net/dwahlin/getting-started-with-es6-using-classes for more details.
by the_archer
Babel + JSX
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;
this._sets = [new Set(), new Set(), new Set()];
}
sets() {
return this._sets;
}
}
let barbellSquat = new Exercise("Barbell Squat");
let updatedBarbellSquat = updateRepsCompleted(barbellSquat);
console.log(updatedBarbellSquat.sets[0]);
function updateRepsCompleted(exercise) {
console.log(exercise.sets.length);
for(var i = 0; i<exercise.sets.length; i++){
exercise.sets[i].repsCompleted = 5;
}
return exercise;
}