我有这个:
var parseFile = function(err, data) {
// I need to access 'myFile'
};
fs.readFile(myFile, 'utf8', parseFile);
如何在别处声明的回调中访问 'myFile'
?
最佳答案
function parseFile(myFile) {
return function (err, data) {
// its a closure bound variable! yay.
}
}
fs.readFile(myFile, "utf8", parseFile(myFile))
关于node.js - 从回调访问调用者参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14790558/