节点js:如何访问方法之间的局部variables
first(); function first(){ second(); third(); } function second(){ var b='second'; } function third(){ console.log(b); }
在尝试访问第三个variablesb时出错,请帮助console.log(b); ^
ReferenceError:b没有定义
如果你想访问b
比你必须将其定义为全局
first(); var b; function first(){ second(); third(); } function second(){ b='second'; } function third(){ console.log(b); } console.log(b);
看我的垃圾箱全球b