Browse Source

HW<9> done

Levshin95 2 years ago
parent
commit
412fd57c91
19 changed files with 158 additions and 0 deletions
  1. 0 0
      HW001/index.html
  2. 0 0
      HW002/index.html
  3. 0 0
      HW002/myjs.js
  4. 0 0
      HW003/index.html
  5. 0 0
      HW003/myjs.js
  6. 0 0
      HW004/index.html
  7. 0 0
      HW004/myjs.js
  8. 0 0
      HW005/index.html
  9. 0 0
      HW005/index.js
  10. 0 0
      HW006/index.html
  11. 0 0
      HW006/index.js
  12. 0 0
      HW007/index.html
  13. 0 0
      HW007/index.js
  14. 0 0
      HW008/index.html
  15. 0 0
      HW008/index.js
  16. 12 0
      HW009/index.html
  17. 92 0
      HW009/index.js
  18. 12 0
      HW010/index.html
  19. 42 0
      HW010/index.js

HW1/index.html → HW001/index.html


HW2/index.html → HW002/index.html


HW2/myjs.js → HW002/myjs.js


HW3/index.html → HW003/index.html


HW3/myjs.js → HW003/myjs.js


HW4/index.html → HW004/index.html


HW4/myjs.js → HW004/myjs.js


HW5/index.html → HW005/index.html


HW5/index.js → HW005/index.js


HW6/index.html → HW006/index.html


HW6/index.js → HW006/index.js


HW7/index.html → HW007/index.html


HW7/index.js → HW007/index.js


HW8/index.html → HW008/index.html


HW8/index.js → HW008/index.js


+ 12 - 0
HW009/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="index.js"></script>
+</body>
+</html>

+ 92 - 0
HW009/index.js

@@ -0,0 +1,92 @@
+/* makeProfileTimer */
+
+function makeProfileTimer() {
+    let time1 = performance.now()
+    return function t() {
+        let time2 = performance.now()
+        return time2 - time1
+    }
+}
+
+var timer = makeProfileTimer()
+alert('Замеряем время работы этого alert');
+alert(timer());
+
+/* makeSaver */
+
+function makeSaver(func){
+    let result = func();
+
+    return function(){
+        return result;
+    }
+}
+
+var saver = makeSaver(Math.random) 
+    var value1 = saver()              
+    var value2 = saver()              
+    value1 === value2                 
+
+    var saver2 = makeSaver(() => console.log('saved function called') || [null, undefined, false, '', 0, Math.random()][Math.ceil(Math.random()*6)])
+    var value3 = saver2()
+    var value4 = saver2()
+
+    value3 === value4 
+    
+    
+    
+    let namePrompt = prompt.bind(window, 'Как тебя зовут?')
+    let nameSaver = makeSaver(namePrompt)
+    alert(`Привет! Prompt еще не было!`)
+    alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
+    alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
+
+/* Final Countdown */
+
+(function (time = 0) {
+    for (let i = 5; i >= 0; i--) {
+        setTimeout(() => {
+            if (i) {
+                console.log(i)
+            } else {
+                console.log("поехали")
+            }
+        }, (time++) * 1000)
+    }
+    })()
+
+/* MyBind */
+
+var myBind = function(fn, context, arr) {
+
+    return function() {
+  let index = 0
+      var fnArgs = [].slice.call(arguments);
+  
+      return fn.apply(context, arr.map(i => {
+  
+  if(i === undefined){
+  let newValue = fnArgs[index]
+  index++
+  return newValue
+  }
+  else return i
+  }));
+    };
+  };
+  
+  var pow5 = myBind(Math.pow, Math, [undefined, 5]) 
+  console.log(pow5(2))
+  
+  var cube = myBind(Math.pow, Math, [undefined, 3])
+  console.log(cube(3))
+  
+  var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9])
+  console.log(chessMin(-1,-5,3,15))
+  
+  var zeroPrompt = myBind(prompt, window, [undefined, "0"])
+  var someNumber = zeroPrompt("Введите число") 
+  
+  console.log(
+  myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'
+  )

+ 12 - 0
HW010/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="index.js"></script>
+</body>
+</html>

+ 42 - 0
HW010/index.js

@@ -0,0 +1,42 @@
+/*  */
+
+function Password(parent, open) {
+    let value = ''
+    let pass = document.createElement('input')
+    let check = document.createElement('input')
+    check.type = 'checkbox'
+    parent.append(pass, check)
+    check.onchange = () => {
+        this.setOpen(check.checked)
+    }
+    //добавить pass oninput, который из pass забирает value, запускает setValue
+    this.getValue = function () {
+        return value
+    }
+    this.setValue = function(value) {
+    // передает value в onchange если он есть
+    }
+    this.getOpen = function () {
+        return open
+    }
+    this.setOpen = function(newOpen) {
+        open = newOpen
+        pass.type = open ? 'text' : 'password'
+        check.checked = open
+        if(typeof this.onOpenChange === 'function') {
+            this.onOpenChange(open)
+        }
+    }
+    this.setOpen(open)
+}
+
+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())