只是一个简单的Javascript问题:
function getStored() {
// Your code here
}
const a = getStored()
let v = 10
console.log(a()); // undefined
console.log(a(v)); // undefined
console.log(a()); // 10
console.log(a()); // 10
console.log(a()); // 10
我想填写getStored,以便其行为与console.logs中显示的注释相同。
根据对闭包的理解,这是我尝试过的事情:
const getStored = function(msg) {
const saved = msg
return function() {
return saved
}
}