|
@@ -9,25 +9,27 @@
|
|
<script>
|
|
<script>
|
|
|
|
|
|
//---------makeProfileTimer
|
|
//---------makeProfileTimer
|
|
- /*function makeProfileTimer(){
|
|
|
|
|
|
+ function makeProfileTimer(){
|
|
let time1=performance.now();
|
|
let time1=performance.now();
|
|
return function(){
|
|
return function(){
|
|
let time2=performance.now();
|
|
let time2=performance.now();
|
|
- alert(time2-time1);
|
|
|
|
|
|
+ return time2-time1;
|
|
|
|
+ //alert(time2-time1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- function fib(n){
|
|
|
|
|
|
+ /*function fib(n){
|
|
if(n==1||n==2){
|
|
if(n==1||n==2){
|
|
return 1;
|
|
return 1;
|
|
}else{
|
|
}else{
|
|
return fib(n-1)+fib(n-2);
|
|
return fib(n-1)+fib(n-2);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
var timer=makeProfileTimer();
|
|
var timer=makeProfileTimer();
|
|
- alert(fib(10));
|
|
|
|
- timer();*/
|
|
|
|
|
|
+ alert('Замеряем время работы этого alert');
|
|
|
|
+ //alert(fib(10));
|
|
|
|
+ alert(timer());
|
|
|
|
|
|
//-----------makeSaver
|
|
//-----------makeSaver
|
|
function makeSaver(fn){
|
|
function makeSaver(fn){
|
|
@@ -56,24 +58,35 @@
|
|
alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
|
|
alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
|
|
|
|
|
|
//-----------Final Countdown
|
|
//-----------Final Countdown
|
|
- /*(function count(){
|
|
|
|
|
|
+ (function count(){
|
|
let x=5;
|
|
let x=5;
|
|
let y=setInterval(function(){
|
|
let y=setInterval(function(){
|
|
console.log(x);
|
|
console.log(x);
|
|
if(x==1){
|
|
if(x==1){
|
|
- console.log('поехали');
|
|
|
|
clearInterval(y);
|
|
clearInterval(y);
|
|
|
|
+ console.log('поехали');
|
|
}
|
|
}
|
|
x--;
|
|
x--;
|
|
},1000)
|
|
},1000)
|
|
- })();*/
|
|
|
|
|
|
+ })();
|
|
|
|
|
|
//------------myBind
|
|
//------------myBind
|
|
- /*function myBind(fn,context,args){
|
|
|
|
- return function(){
|
|
|
|
|
|
+ function myBind(fn,context,args){
|
|
|
|
+ /*return function(){
|
|
let args2=Object.assign(args,arguments);
|
|
let args2=Object.assign(args,arguments);
|
|
return fn.call(context,...args2);
|
|
return fn.call(context,...args2);
|
|
|
|
+ }*/
|
|
|
|
+ let arr=[...args];
|
|
|
|
+ return function(){
|
|
|
|
+ let arr2=Array.from(arguments);
|
|
|
|
+ for(let i=0;i<arr.length;i++){
|
|
|
|
+ if(!arr[i]){
|
|
|
|
+ arr[i]=arr2.shift();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return fn.call(context,...arr);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
var pow5 = myBind(Math.pow, Math, [undefined, 5]);
|
|
var pow5 = myBind(Math.pow, Math, [undefined, 5]);
|
|
@@ -82,7 +95,7 @@
|
|
console.log(cube(3)); //27
|
|
console.log(cube(3)); //27
|
|
|
|
|
|
var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9]);
|
|
var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9]);
|
|
- console.log(chessMin(-1,-5,3,15)); //NaN ???
|
|
|
|
|
|
+ console.log(chessMin(-1,-5,3,15)); //-5
|
|
|
|
|
|
var zeroPrompt = myBind(prompt, window, [undefined, "0"]);
|
|
var zeroPrompt = myBind(prompt, window, [undefined, "0"]);
|
|
|
|
|
|
@@ -90,7 +103,7 @@
|
|
console.log(someNumber);
|
|
console.log(someNumber);
|
|
|
|
|
|
|
|
|
|
- console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef');*/
|
|
|
|
|
|
+ console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'); //true
|
|
</script>
|
|
</script>
|
|
</body>
|
|
</body>
|
|
</html>
|
|
</html>
|