|
@@ -26,30 +26,38 @@
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
- var timer=makeProfileTimer();
|
|
|
- alert('Замеряем время работы этого alert');
|
|
|
+ //var timer=makeProfileTimer();
|
|
|
+ //alert('Замеряем время работы этого alert');
|
|
|
//alert(fib(10));
|
|
|
- alert(timer());
|
|
|
+ //alert(timer());
|
|
|
|
|
|
//-----------makeSaver
|
|
|
function makeSaver(fn){
|
|
|
- let x=fn();
|
|
|
+ let called=false;
|
|
|
+ let x=fn;
|
|
|
+ let a;
|
|
|
return function(){
|
|
|
- return x;
|
|
|
+ if(!called){
|
|
|
+ a=x();
|
|
|
+ called=true;
|
|
|
+ return a;
|
|
|
+ }else{
|
|
|
+ return a;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var saver = makeSaver(Math.random);
|
|
|
var value1 = saver();
|
|
|
var value2 = saver();
|
|
|
- console.log(value1+" "+value2);
|
|
|
- console.log(value1 === value2);
|
|
|
+ console.log(value1+" "+value2);
|
|
|
+ console.log(value1 === value2); //true
|
|
|
|
|
|
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);
|
|
|
+ console.log(value3 === value4); //true
|
|
|
|
|
|
let namePrompt = prompt.bind(window, 'Как тебя зовут?')
|
|
|
let nameSaver = makeSaver(namePrompt)
|
|
@@ -57,8 +65,9 @@
|
|
|
alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
|
|
|
alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
|
|
|
|
|
|
+
|
|
|
//-----------Final Countdown
|
|
|
- (function count(){
|
|
|
+ /*(function count(){
|
|
|
let x=5;
|
|
|
let y=setInterval(function(){
|
|
|
console.log(x);
|
|
@@ -68,28 +77,28 @@
|
|
|
}
|
|
|
x--;
|
|
|
},1000)
|
|
|
- })();
|
|
|
+ })();*/
|
|
|
+
|
|
|
|
|
|
//------------myBind
|
|
|
function myBind(fn,context,args){
|
|
|
- /*return function(){
|
|
|
- let args2=Object.assign(args,arguments);
|
|
|
- return fn.call(context,...args2);
|
|
|
- }*/
|
|
|
+ //return function(){
|
|
|
+ //let args2=Object.assign(args,arguments);
|
|
|
+ //return fn.call(context,...args2);
|
|
|
+ //}
|
|
|
let arr=[...args];
|
|
|
return function(){
|
|
|
- let arr2=Array.from(arguments);
|
|
|
+ arguments.__proto__=Array.prototype;
|
|
|
for(let i=0;i<arr.length;i++){
|
|
|
- if(!arr[i]){
|
|
|
- arr[i]=arr2.shift();
|
|
|
+ if(arr[i]===undefined){
|
|
|
+ arr[i]=arguments.shift();
|
|
|
}
|
|
|
}
|
|
|
- return fn.call(context,...arr);
|
|
|
+ return fn.apply(context,arr);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- var pow5 = myBind(Math.pow, Math, [undefined, 5]);
|
|
|
+ /*var pow5 = myBind(Math.pow, Math, [undefined, 5]);
|
|
|
var cube = myBind(Math.pow, Math, [undefined, 3]);
|
|
|
console.log(pow5(2)); //32
|
|
|
console.log(cube(3)); //27
|
|
@@ -100,10 +109,10 @@
|
|
|
var zeroPrompt = myBind(prompt, window, [undefined, "0"]);
|
|
|
|
|
|
var someNumber = zeroPrompt("Введите число");
|
|
|
- console.log(someNumber);
|
|
|
+ console.log(someNumber); //0
|
|
|
|
|
|
|
|
|
- console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'); //true
|
|
|
+ console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'); //true*/
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|