Vika 3 tahun lalu
induk
melakukan
dfc416dc42
3 mengubah file dengan 108 tambahan dan 0 penghapusan
  1. 13 0
      js10/index.html
  2. 95 0
      js10/main.js
  3. 0 0
      js10/style.css

+ 13 - 0
js10/index.html

@@ -0,0 +1,13 @@
+<!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>
+  <link href="style.css" rel="stylesheet">
+</head>
+<body>
+  <script src="main.js"></script>
+</body>
+</html>

+ 95 - 0
js10/main.js

@@ -0,0 +1,95 @@
+// let countTime = 0;
+// function makeProfileTimer () {
+//   countTime = performance.now();
+//   return () => performance.now() -  countTime;
+// }
+// var timer = makeProfileTimer(); 
+// alert('Замеряем время работы этого alert'); 
+// alert(timer());
+
+
+
+//makeSaver
+// debugger;
+// function makeSaver (arg) {
+//   let storage = [];
+  
+//   return () => { 
+//     if (storage.length) {
+//       let elemArr = arg();
+//       storage.push(elemArr);
+//     }
+    
+//     return storage[0];
+//   }
+// }
+
+// var saver = makeSaver(Math.random);
+// var value1 = saver();
+// var value2 = saver();  
+// console.log(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()
+
+// console.log(value3 === value4);
+
+// let namePrompt = prompt.bind(window, 'Как тебя зовут?')
+// let nameSaver = makeSaver(namePrompt)
+// alert(`Привет! Prompt еще не было!`)
+// alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
+// alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
+
+
+
+//Final Countdown
+ 
+// function SelfInvoked (arg) {
+//   console.log(arg);
+//   arg = arg -1;
+    
+//   if (arg === 0) {
+//     setTimeout(SelfInvoked, 1000, 'поехали!');
+//     return;
+//   }
+//   if(arg) {
+//     return setTimeout(SelfInvoked, 1000, arg);
+//   }
+//   return;
+// }
+
+// SelfInvoked(5);
+
+// myBind
+//debugger;
+function myBind (func, obj, arr) {
+  
+  return function (...arg) {
+      let indexArg = 0;
+   
+    for (let i = 0; i < arr.length; i++) {
+      if (!arr[i]) {
+        arr[i] = arg[indexArg];
+        indexArg++;
+      }
+    }
+    let result = func.apply(obj, arr)
+    return result;
+  }
+  
+}
+
+var pow5 = myBind(Math.pow, Math, [undefined, 5]);
+var cube = myBind(Math.pow, Math, [undefined, 3]);
+
+console.log(pow5(2));
+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')
+

+ 0 - 0
js10/style.css