gpt4 book ai didi

javascript - "object is not a function"错误?

转载 作者:太空宇宙 更新时间:2023-11-04 03:11:43 25 4
gpt4 key购买 nike

我有一个使用async的node.js应用程序一个接一个地调用方法。由于某种原因,当我尝试进入 waterfall 的第二层时,我的应用程序抛出以下错误:

TypeError: object is not a function

我有以下代码,即coffescript(如果有人需要,我可以获取javascript):

async.waterfall([
(callback) =>
console.log 'call getSurveyTitle'
@getSurveyTitle (surveyTitle) =>
fileName = 'Results_' + surveyTitle + '_' + dateString + '.csv'
filePath = path.resolve process.env.PWD, 'static', @tempDir, fileName
csv.to(fs.createWriteStream(filePath))
callback(null, null)
,
(callback) =>
@createHeaderRow (headerRow) =>
headerText = _.map headerRow, (row) =>
row.text
csv.write headerText
console.log 'before' #gets here and then throws error
callback(null,headerRow)
,
(headerRow, callback) =>
console.log 'after'
@createRows headerRow, (callback) =>
callback(null,null)
], (err, result) =>
console.log "waterfall done!"
)

我对 Node 和异步相当陌生,所以我有一种感觉,我只是忽略了一些明显的东西。谁能看到我正在做的事情可能会导致此错误?

最佳答案

对于waterfall,第一个error之后的任何callback参数都将传递到下一个任务,包括null:

async.waterfall([
(callback) =>
callback(null, null, null)
,
(callback) =>
console.log callback # null
console.log arguments # { 0: null, 1: null, 2: [Function], length: 3 }
])

如果您不希望将任何值传递给下一个任务,只需使用error参数调用callback即可:

callback(null)

或者为第一个参数设置一个名称,这样回调就是第二个:

(_, callback) =>
@createHeaderRow (headerRow) =>
# ...

关于javascript - "object is not a function"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15230458/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com