|
@@ -1,19 +1,23 @@
|
|
// makeProfileTimer
|
|
// makeProfileTimer
|
|
function makeProfileTimer() {
|
|
function makeProfileTimer() {
|
|
|
|
+ let old = performance.now()
|
|
function remembered() {
|
|
function remembered() {
|
|
- return performance.now()
|
|
|
|
|
|
+ return performance.now() - old
|
|
}
|
|
}
|
|
return remembered
|
|
return remembered
|
|
}
|
|
}
|
|
-
|
|
|
|
let timer = makeProfileTimer()
|
|
let timer = makeProfileTimer()
|
|
alert('hello')
|
|
alert('hello')
|
|
alert(timer())
|
|
alert(timer())
|
|
|
|
|
|
// makeSaver
|
|
// makeSaver
|
|
function makeSaver(func) {
|
|
function makeSaver(func) {
|
|
- let value = func()
|
|
|
|
- return function invoker() {
|
|
|
|
|
|
+ let value = func
|
|
|
|
+ return () => {
|
|
|
|
+ function vault() {
|
|
|
|
+ value = value()
|
|
|
|
+ }
|
|
|
|
+ if(typeof value === 'function') vault()
|
|
return value
|
|
return value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -29,9 +33,17 @@ console.log('is equal?', value1 === value2) // всегда true
|
|
var saver2 = makeSaver(() => console.log('saved function called') || [null, undefined, false, '', 0, Math.random()][Math.ceil(Math.random() * 6)])
|
|
var saver2 = makeSaver(() => console.log('saved function called') || [null, undefined, false, '', 0, Math.random()][Math.ceil(Math.random() * 6)])
|
|
var value3 = saver2()
|
|
var value3 = saver2()
|
|
var value4 = saver2()
|
|
var value4 = saver2()
|
|
-
|
|
|
|
|
|
+console.log('3 & 4', value3, value4)
|
|
console.log('is equal?', value3 === value4) // тоже должно быть true
|
|
console.log('is equal?', value3 === value4) // тоже должно быть true
|
|
|
|
|
|
|
|
+let namePrompt = prompt.bind(window, 'Как тебя зовут?')
|
|
|
|
+let nameSaver = makeSaver(namePrompt)
|
|
|
|
+alert(`Привет! Prompt еще не было!`)
|
|
|
|
+alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
|
|
|
|
+alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// Final Countdown
|
|
// Final Countdown
|
|
var finalCountdown = (function (sec) {
|
|
var finalCountdown = (function (sec) {
|
|
var counter = sec;
|
|
var counter = sec;
|