← Назад
class Person {
constructor (name, family, age) {
this.name = name
this.family = family
this.age = age
this.state = 'normal'
}
greeting () {
if (this.state === 'normal') {
console.log(`Добрый день. Я ${this.name} ${this.family}.`)
}
else if (this.state === 'angry') {
console.log(`ЧТО ${this.name.toUpperCase()}?! Я УЖЕ ${this.age} ${this.name.toUpperCase()}!`)
}
}
}
const person = new Person('Алексей', 'Данчин', 27)
person.greeting() // Добрый день. Я Алексей Данчин.
person.state = 'angry'
person.greeting() // ЧТО АЛЕКСЕЙ?! Я УЖЕ 27 АЛЕКСЕЙ!