我在的NodeJS定義了兩個簡單的功能函數組成:的ReferenceError:不定義的錯誤,而試圖使用
function findEntityDetailsAsIs(modelname, callback) {
modelname.find({}, function(error, result) {
if (error)
callback (error, null);
else {
//console.log(result);
callback (null, result);
}
});
};
這是我的第一個功能,另一個功能是
function printEntitydetails(error, entitydetails, callback) {
console.log(entitydetails);
}
我試圖將這些功能稱爲
findEntityDetailsAsIs(fieldLabel, printEntitydetails(error, entitydetails));
但是,當我嘗試運行此函數調用它拋出一個錯誤
ReferenceError: error is not defined
但錯誤只是作爲我從回調傳遞的佔位符對象。
findEntityDetailsAsIs(fieldLabel, printEntitydetails(entitydetails));
我試過在通話中跳過錯誤,但這次它給出了這個錯誤。
ReferenceError: entitydetails not is not defined
按我的知識findEntityDetailsAsIs
應該提供entitydetails
的背景下,爲我提供了一個callback(null, result)
。
當你在函數名後面添加圓括號時,它會調用它並將其輸出作爲回調函數傳遞。嘗試'printEntitydetails.bind(null,error,entitydetails)' – Rajesh