【发布时间】:2013-12-08 14:32:42
【问题描述】:
我有这个功能:
exports.readPartial = function(html, values, response) {
fs.readFile(__dirname + "/../html/partials/" + html, function(error, file) {
if(error) { this.loadError(response, error); }
else {
console.log("\t--> partial found: " + file);
return file; // FILE VALUE
}
});
}
当该函数被调用时,它应该返回“file”的值。但是,当调用return file; 时,我实际上返回了我作为参数传递的匿名函数中的值。
在使用 nodejs 进行异步编程时返回这个值的正确方法是什么?
使用var that = this; ?
对这种编程风格感到很困惑。
【问题讨论】:
标签: node.js