|
@@ -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')
|
|
|
|
+
|