Browse Source

Загрузить файлы ''

Daria10 3 năm trước cách đây
mục cha
commit
c8835f8947
2 tập tin đã thay đổi với 70 bổ sung0 xóa
  1. 12 0
      index.html
  2. 58 0
      main.js

+ 12 - 0
index.html

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

+ 58 - 0
main.js

@@ -0,0 +1,58 @@
+// /////////////////////////makeProfileTimer
+function makeProfileTimer() {
+    let startTime = performance.now();
+    return function () {
+        return performance.now() - startTime;
+    }
+};
+const timer = makeProfileTimer();
+
+alert('Замеряем время работы этого alert');
+alert(`Time for this alert running is: ${timer()}`);
+
+// ////////////////////// makeSaver
+function makeSaver(func) {
+    let run1 = true;
+    let saveResult;
+    return function () {
+        if (run1) {
+            saveResult = func();
+            run1 = false;
+            console.log(`Result is saved: ${saveResult}`);
+        }
+        return saveResult;
+    }
+}
+
+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;
+
+// //////////////////////////Final Countdown
+function finalCountdown() {
+    for (let i = 0; i < 5; i++) {
+        setTimeout(() => console.log(5 - i), 1000 * i)
+    }
+    setTimeout(() => console.log("поехали !"), 5000)
+}
+
+// ////////////////////////////myBind
+function myBind(func, tempThis, tempArray) {
+    return function (...arguments) {
+        let i = 0;
+        let newTempArray = tempArray.map((value) => (value === undefined ? arguments[i++] : value));
+
+        return func.apply(tempThis, newTempArray); 
+    };
+}
+
+
+