123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //Person Constructor
- {
- function Person(name, surname, fatherName="") {
- this.name = name
- this.surname = surname
- this.fatherName = fatherName
- this.getFullName = () => `${this.name} ${this.fatherName} ${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 Person(name, surname, fatherName="") {
- this.name = name
- this.surname = surname
- this.fatherName = fatherName
-
- }
- Person.prototype.getFullName = function(){
- return `${this.name} ${this.fatherName} ${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()) //Анна Иванова
- }
- //Store
- //Password
- {
- function Password(parent, open){
- this.open = open
- let inputPassword = document.createElement('input')
- parent.append(inputPassword)
- let inputCheck = document.createElement("input")
- inputCheck.type = 'checkbox'
- parent.append(inputCheck)
- this.setValue = (value) => inputPassword.value = value
- this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
- this.getValue = () => inputPassword.value
- this.getOpen = () => inputPassword.type
- inputCheck.onchange = () => this.setOpen(inputCheck.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){
- this.open = open
- let inputPassword = document.createElement('input')
- parent.append(inputPassword)
- let inputCheck = document.createElement("input")
- inputCheck.type = 'checkbox'
- parent.append(inputCheck)
- this.setValue = (value) => inputPassword.value = value
- this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
- this.getValue = () => inputPassword.value
- this.getOpen = () => inputPassword.type
- inputCheck.onchange = () => this.setOpen(inputCheck.checked)
- }
- function loginForm(parent) {
- let inputLogin = document.createElement('input')
- inputLogin.type = 'text'
- parent.append(inputLogin)
- this.password = new Password(document.body,true)
- let buttonLog = document.createElement('button')
- buttonLog.innerText = 'Submit'
- parent.append(buttonLog)
- this.setValue = (value) => inputLogin.value = value
- this.getValue = () => this.password
-
- inputLogin.onchange = eve => {
- checkResult(eve.target.value,this.password.getValue())
- }
-
- this.password.onChange = value => {
- checkResult(value,inputLogin.value)
- }
- const checkResult = () => {
- if(inputLogin.value && this.password.getValue()) {
- buttonLog.disabled = false
- }
- else {
- buttonLog.disabled = true
- }
- }
- this.onChange = () => {
- inputLogin.onchange = (eve) => {
- this.onChange(eve.target.value)
- }
- }
- inputLogin.oninput = checkResult
- this.password.oninput = checkResult
- }
- let p = new loginForm(document.body, true)
-
- p.onChange = data => console.log(data)
- p.onOpenChange = open => console.log(open)
- }
-
- //LoginForm Constructor
- {
- function Password(parent, open){
- this.open = open
- let inputPassword = document.createElement('input')
- parent.append(inputPassword)
- let inputCheck = document.createElement("input")
- inputCheck.type = 'checkbox'
- parent.append(inputCheck)
- this.setValue = (value) => inputPassword.value = value
- this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
- this.getValue = () => inputPassword.value
- this.getOpen = () => inputPassword.type
- inputCheck.onchange = () => this.setOpen(inputCheck.checked)
- }
- function loginForm(parent) {
- let inputLogin = document.createElement('input')
- inputLogin.type = 'text'
- parent.append(inputLogin)
- this.password = new Password(document.body,true)
- let buttonLog = document.createElement('button')
- buttonLog.innerText = 'Submit'
- parent.append(buttonLog)
- this.setValue = (value) => inputLogin.value = value
- this.getValue = () => this.password
-
- inputLogin.onchange = eve => {
- checkResult(eve.target.value,this.password.getValue())
- }
-
- this.password.onChange = value => {
- checkResult(value,inputLogin.value)
- }
- const checkResult = () => {
- if(inputLogin.value && this.password.getValue()) {
- buttonLog.disabled = false
- }
- else {
- buttonLog.disabled = true
- }
- }
- this.onChange = () => {
- inputLogin.onchange = (eve) => {
- this.onChange(eve.target.value)
- }
- }
- inputLogin.oninput = checkResult
- this.password.oninput = checkResult
- }
- function finalForm (parent,open) {
- this.log = new loginForm(document.body)
- }
- let p = new finalForm(document.body, true)
-
- p.onChange = data => console.log(data)
- p.onOpenChange = open => console.log(open)
- }
|