12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // /////////////////////////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);
- };
- }
|