我在一个node.js脚本上工作,我无法调用函数以外的变量。 File.name完美运行在engine.on ready函数中,但不会在engine.on空闲函数中运行。无法在函数之外调用变量?
engine.on('ready', function() {
engine.files.forEach(function (file) {
io.emit('chat message', "downloading " + file.name);
file.select()
})
engine.on('idle', function() {
io.emit('chat message',"files '" + file.name + "' downloaded");
});
});
我该如何让file.name成为一个可以在所有函数中使用的全局变量?
只需使用:'VAR东西= file.name' –