node,express和javascript的新手。
以下是index.js
文件夹中routers
的代码。
我想传递或访问res
函数中的handleImport
变量。
function handleImport( err, stat)
{
if(err == null) {
// Do something with res
res.end();
}
else{
// Do something with res
res.end();
}
}
router.get('/traveler', function(req, res, next) {
var import_path = req.query.drawing;
fs.stat(import_path,handleImport);
});
似乎bind()可能是我之后的,但找不到如何正确使用它的好资料。
答案 0 :(得分:0)
AFAICS,最好的解决方案是使用匿名功能。
router.get('/traveler', function(req, res, next) {
var import_path = req.query.drawing;
fs.stat(import_path, function (err, stat) {
if (err == null) {
// Do something with res
res.end();
} else {
// Do something with res
res.end();
}
});
});
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name