我有这个:
var parseFile = function(err, data) {
// I need to access 'myFile'
};
fs.readFile(myFile, 'utf8', parseFile);
如何在其他地方声明的回调中访问'myFile'
?
答案 0 :(得分:6)
function parseFile(myFile) {
return function (err, data) {
// its a closure bound variable! yay.
}
}
fs.readFile(myFile, "utf8", parseFile(myFile))