Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 891 Bytes

State.md

File metadata and controls

35 lines (25 loc) · 891 Bytes

← Назад

State / Состояние

State

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 АЛЕКСЕЙ!