문제

Hello I am using connect and have:

var app = connect()
 .use(connect.static(directory))
 .use(function(req,res) {
  switch (req.url)
  {
   case '/query':
    exportFunc.query("myquery", res.end);
    break;
  }
}

-- exportFunc.js --
exports.query= function(query, cb) {
 queryServer(query, cb);
}

var queryServer = function(query, cb) {
 cb("MyQueryResult");
}

But I get an error that cb cannot be determined what object it is. Do I need to cast this object into its correct type?

도움이 되었습니까?

해결책

You're not calling the function with the right context (this in the function). You can fix it by replacing

 exportFunc.query("myquery", res.end);

with

 exportFunc.query("myquery", res.end.bind(res));

or

 exportFunc.query("myquery", function(){ res.end() });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top