我需要在嵌套函数中访问全局变量,我该怎么做?let x = 0function one() { console.log(x)}function two() { two()}应该记录为0,但出现错误“ x未定义”
1 回答

PIPIONE
TA贡献1829条经验 获得超9个赞
你的函数two被调用本身-你需要调用one在two。您还必须致电two:
let x = 0
function one() {
console.log(x);
}
function two() {
one();
}
two();
添加回答
举报
0/150
提交
取消