2

我有这个:

var parseFile = function(err, data) {
 // I need to access 'myFile'
};
fs.readFile(myFile, 'utf8', parseFile);

如何'myFile'在其他地方声明的回调中访问?

4

1 回答 1

6
function parseFile(myFile) {
  return function (err, data) {
    // its a closure bound variable! yay.
  }
}

fs.readFile(myFile, "utf8", parseFile(myFile))
于 2013-02-09T19:33:17.320 回答