let x = "value before setTimeout";
function cb() {
console.log(currentValue);
}
setTimeout(cb, 3000);
x = "updated value";
如何借助回调函数打印“setTimoeout 之前的值”。如何捕获旧值并使用它?
将其存储为临时系数:
let a = 20
function log(a) {
console.log('a is: ' + a)
}
setTimeout(log, 1000, a)
a = 43