this & array
by Maxim_Wolf
JavaScript
const cat = {
lives: 9,
name: 'кекс',
say(){
return `кличка ${this.name}. у меня ${this.lives} жизней`;
},
};
const dog = {
lastName: 'Шариков',
convictions: 3,
specialty: "балалайка",
say(){
return `${this.lastName}! играю на ${this.specialty}. у меня ${this.convictions} судимости`;
}
}
const list = [cat, dog];
list.forEach((speaker)=>console.log(speaker.say()))