I have this class Programmer extends Person
and this function is stored inside the class
code () {console.log (`${this.name} is coding`)}
I then created an array outside of the class declaration
const programmers = [new Programmer("dom", 56, 12), new Programmer("jeff", 24, 4)]
And also a function
function developSoftware (programmers) {
for (let programmer in programmers) {
programmer.code()
}
}
Why does the error programmer.code is not a function
when I use a for-in loop instead of a for-of loop? what's the logic behind? I know that for arrays one should use a for-of
loop
Also how do I format the code in StackOverflow such that the post shows line breaks in between the code?
class Programmer
{
code () {
console.log (`${this.name} is coding`);
}
}
const programmers = [new Programmer("dom", 56, 12), new Programmer("jeff", 24, 4)]
function developSoftware (programmers) {
for (let programmer of programmers) {
programmer.code()
}
}
developSoftware(programmers);