先举个例子说:const testFun = () => {
let testParams
const sonFun = () => {
testParams = 3
}
console.log(testParams)
}
像上面这样的写法,我怎么才能console出testParams的值呢?
先举个例子说:const testFun = () => {
let testParams
const sonFun = () => {
testParams = 3
}
console.log(testParams)
}
像上面这样的写法,我怎么才能console出testParams的值呢?
你这赋值根本就没执行嘛
let testParams
const sonFun = () => {
testParams = 3
}
sonFun()
console.log(testParams)
const testFun = () => {
let testParams
const sonFun = () => {
testParams = 3
}
sonFun()
console.log(testParams)
}
testFun()
let testParams
const sonFun = () => {
testParams = 3
}
sonFun();
console.log(testParams)
这个箭头函数的作用域,在这段代码里面怕是没有提现出来
13 回答12.8k 阅读
7 回答2k 阅读
3 回答1.1k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
6 回答922 阅读✓ 已解决
6 回答1.1k 阅读
2 回答1.3k 阅读✓ 已解决
首先你得先执行了sonFun这个方法,你才能给testParams赋上值