//Person Constructor { class Person { constructor(name,surname){ this.name = name this.surname = surname } getFullName(){ if(this.fatherName){ return `${this.name} ${this.fatherName} ${this.surname}` } else{return `${this.name} ${this.surname}`} } } const a = new Person("Вася", "Пупкин") const b = new Person("Анна", "Иванова") const c = new Person("Елизавета", "Петрова") console.log(a.getFullName()) //Вася Пупкин a.fatherName = 'Иванович' console.log(a.getFullName()) //Вася Иванович Пупкин console.log(b.getFullName()) //Анна Иванова } //Person Prototype { function createPerson(name,surname){ class Person { constructor(name,surname){ this.name = name this.surname = surname } getFullName(){ if(this.fatherName){ return `${this.name} ${this.fatherName} ${this.surname}` } else{return `${this.name} ${this.surname}`} } } return new Person(name, surname) } const a = createPerson("Вася", "Пупкин") const b = createPerson("Анна", "Иванова") const c = createPerson("Елизавета", "Петрова") console.log(a.getFullName()) //Вася Пупкин a.fatherName = 'Иванович' console.log(a.getFullName()) //Вася Иванович Пупкин console.log(b.getFullName()) //Анна Иванова } //Store { function createStore(reducer){ let state = reducer(undefined, {}) let cbs = [] function Store(){ this.getState = () => state this.subscribe = cb => (cbs.push(cb), () => cbs = cbs.filter(c => c !== cb)) this.dispatch = action => { const newState = reducer(state, action) if (newState !== state){ state = newState for (let cb of cbs) cb() } } } return new Store() } } //Password { function Password(parent, open) { let input = document.createElement('input') let checkBox = document.createElement('input') checkBox.type = 'checkbox' parent.append(input, checkBox) this.setValue =(value)=> input.value = value this.setOpen =(open)=> input.type = open ?'text':'password' this.getValue =()=> input.value this.getOpen =()=> input.type checkBox.onchange =()=>this.setOpen(checkBox.checked) } let p = new Password(document.body, true) p.onChange = data => console.log(data) p.onOpenChange = open => console.log(open) p.setValue('qwerty') console.log(p.getValue()) p.setOpen(false) console.log(p.getOpen()) } //LoginForm { function Password(parent, open) { let inputPass = document.createElement('input') let inputLogin = document.createElement('input') let checkBox = document.createElement('input') let button = document.createElement('button') button.innerText='Войти' button.disabled=true checkBox.type = 'checkbox' parent.append(inputPass,inputLogin,checkBox,button) this.setValue =(value)=> inputPass.value = value this.setOpen =(open)=> inputPass.type= open ?'text':'password' this.getValue =()=> inputPass.value this.getOpen =()=> inputPass.type checkBox.onchange =()=>this.setOpen(checkBox.checked) function btn (){ if(inputPass.value && inputLogin.value){ button.disabled=false } else{ button.disabled=true } } inputPass.oninput = btn inputLogin.oninput = btn } let p = new Password(document.body, true) p.onChange = data => console.log(data) p.onOpenChange = open => console.log(open) p.setValue('qwerty') console.log(p.getValue()) p.setOpen(false) console.log(p.getOpen()) }