Javascript Sails错误:未定义不是函数
我试图将sails实现为中间服务器,但无法通过Javascript Sails错误:未定义不是函数,javascript,node.js,sails.js,Javascript,Node.js,Sails.js,我试图将sails实现为中间服务器,但无法通过sailsserver进行api调用。当api调用成功时,它工作良好,但当api调用失败时,它将不工作。 它给出了这个错误 this.error(res,err); ^ TypeError: undefined is not a function at error (/Users/nitin.tiwari/owner-app-backend/api/controllers/ApiController.js:26:12) a
sails
server进行api调用。当api调用成功时,它工作良好,但当api调用失败时,它将不工作。
它给出了这个错误
this.error(res,err);
^
TypeError: undefined is not a function
at error (/Users/nitin.tiwari/owner-app-backend/api/controllers/ApiController.js:26:12)
at IncomingMessage.<anonymous> (/Users/nitin.tiwari/owner-app-backend/api/services/XHR.js:54:11)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickDomainCallback (node.js:381:11)
我已经实现了error函数,但它显示为未定义。我现在无法调试它。这是因为您在
错误
回调中使用了此函数,其中此函数的引用已更改,因此未定义此错误。为此,请将此的引用存储在
一些变量,并使用该变量代替此变量
var protocol = 'http';
var self = this;
var success = function(response){
return res.ok(response);
},
error = function(err){
self.error(res,err);
};
var protocol = 'http';
var self = this;
var success = function(response){
return res.ok(response);
},
error = function(err){
self.error(res,err);
};