If I have a list of 5 people's names, such as Sam, Ash, Moe, Billy, Kenzi, and want each name to have properties like doneHomework
and lazy
using a class:
class Person {
constructor() {
this.doneHomeWork = 0;
this.lazy = false;
}
}
Instead of manually assigning each name like this:
const Sam = new Person();
const Ash = new Person();
const Moe = new Person();
const Billy = new Person();
const Kenzi = new Person();
I thought about doing this:
listNames.forEach(name => {
name = new Person();
})
But my ESLint is showing an error:
Assignment to function parameter 'name' - no-param-reassign
This may seem trivial, but I'm having difficulty refactoring this code.