main.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //Person Constructor
  2. {
  3. function Person(name, surname, fatherName="") {
  4. this.name = name
  5. this.surname = surname
  6. this.fatherName = fatherName
  7. this.getFullName = () => `${this.name} ${this.fatherName} ${this.surname} `
  8. }
  9. const a = new Person("Вася", "Пупкин")
  10. const b = new Person("Анна", "Иванова")
  11. const c = new Person("Елизавета", "Петрова")
  12. console.log(a.getFullName()) //Вася Пупкин
  13. a.fatherName = 'Иванович'
  14. console.log(a.getFullName()) //Вася Иванович Пупкин
  15. console.log(b.getFullName()) //Анна Иванова
  16. }
  17. //Person Prototype
  18. {
  19. function Person(name, surname, fatherName="") {
  20. this.name = name
  21. this.surname = surname
  22. this.fatherName = fatherName
  23. }
  24. Person.prototype.getFullName = function(){
  25. return `${this.name} ${this.fatherName} ${this.surname} `
  26. }
  27. const a = new Person("Вася", "Пупкин")
  28. const b = new Person("Анна", "Иванова")
  29. const c = new Person("Елизавета", "Петрова")
  30. console.log(a.getFullName()) //Вася Пупкин
  31. a.fatherName = 'Иванович'
  32. console.log(a.getFullName()) //Вася Иванович Пупкин
  33. console.log(b.getFullName()) //Анна Иванова
  34. }
  35. //Store
  36. //Password
  37. {
  38. function Password(parent, open){
  39. this.open = open
  40. let inputPassword = document.createElement('input')
  41. parent.append(inputPassword)
  42. let inputCheck = document.createElement("input")
  43. inputCheck.type = 'checkbox'
  44. parent.append(inputCheck)
  45. this.setValue = (value) => inputPassword.value = value
  46. this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
  47. this.getValue = () => inputPassword.value
  48. this.getOpen = () => inputPassword.type
  49. inputCheck.onchange = () => this.setOpen(inputCheck.checked)
  50. }
  51. let p = new Password(document.body, true)
  52. p.onChange = data => console.log(data)
  53. p.onOpenChange = open => console.log(open)
  54. p.setValue('qwerty')
  55. console.log(p.getValue())
  56. p.setOpen(false)
  57. console.log(p.getOpen())
  58. }
  59. //LoginForm
  60. {
  61. function Password(parent, open){
  62. this.open = open
  63. let inputPassword = document.createElement('input')
  64. parent.append(inputPassword)
  65. let inputCheck = document.createElement("input")
  66. inputCheck.type = 'checkbox'
  67. parent.append(inputCheck)
  68. this.setValue = (value) => inputPassword.value = value
  69. this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
  70. this.getValue = () => inputPassword.value
  71. this.getOpen = () => inputPassword.type
  72. inputCheck.onchange = () => this.setOpen(inputCheck.checked)
  73. }
  74. function loginForm(parent) {
  75. let inputLogin = document.createElement('input')
  76. inputLogin.type = 'text'
  77. parent.append(inputLogin)
  78. this.password = new Password(document.body,true)
  79. let buttonLog = document.createElement('button')
  80. buttonLog.innerText = 'Submit'
  81. parent.append(buttonLog)
  82. this.setValue = (value) => inputLogin.value = value
  83. this.getValue = () => this.password
  84. inputLogin.onchange = eve => {
  85. checkResult(eve.target.value,this.password.getValue())
  86. }
  87. this.password.onChange = value => {
  88. checkResult(value,inputLogin.value)
  89. }
  90. const checkResult = () => {
  91. if(inputLogin.value && this.password.getValue()) {
  92. buttonLog.disabled = false
  93. }
  94. else {
  95. buttonLog.disabled = true
  96. }
  97. }
  98. this.onChange = () => {
  99. inputLogin.onchange = (eve) => {
  100. this.onChange(eve.target.value)
  101. }
  102. }
  103. inputLogin.oninput = checkResult
  104. this.password.oninput = checkResult
  105. }
  106. let p = new loginForm(document.body, true)
  107. p.onChange = data => console.log(data)
  108. p.onOpenChange = open => console.log(open)
  109. }
  110. //LoginForm Constructor
  111. {
  112. function Password(parent, open){
  113. this.open = open
  114. let inputPassword = document.createElement('input')
  115. parent.append(inputPassword)
  116. let inputCheck = document.createElement("input")
  117. inputCheck.type = 'checkbox'
  118. parent.append(inputCheck)
  119. this.setValue = (value) => inputPassword.value = value
  120. this.setOpen = (open) => inputPassword.type = open ? 'text' : 'password'
  121. this.getValue = () => inputPassword.value
  122. this.getOpen = () => inputPassword.type
  123. inputCheck.onchange = () => this.setOpen(inputCheck.checked)
  124. }
  125. function loginForm(parent) {
  126. let inputLogin = document.createElement('input')
  127. inputLogin.type = 'text'
  128. parent.append(inputLogin)
  129. this.password = new Password(document.body,true)
  130. let buttonLog = document.createElement('button')
  131. buttonLog.innerText = 'Submit'
  132. parent.append(buttonLog)
  133. this.setValue = (value) => inputLogin.value = value
  134. this.getValue = () => this.password
  135. inputLogin.onchange = eve => {
  136. checkResult(eve.target.value,this.password.getValue())
  137. }
  138. this.password.onChange = value => {
  139. checkResult(value,inputLogin.value)
  140. }
  141. const checkResult = () => {
  142. if(inputLogin.value && this.password.getValue()) {
  143. buttonLog.disabled = false
  144. }
  145. else {
  146. buttonLog.disabled = true
  147. }
  148. }
  149. this.onChange = () => {
  150. inputLogin.onchange = (eve) => {
  151. this.onChange(eve.target.value)
  152. }
  153. }
  154. inputLogin.oninput = checkResult
  155. this.password.oninput = checkResult
  156. }
  157. function finalForm (parent,open) {
  158. this.log = new loginForm(document.body)
  159. }
  160. let p = new finalForm(document.body, true)
  161. p.onChange = data => console.log(data)
  162. p.onOpenChange = open => console.log(open)
  163. }