gpt4 book ai didi

javascript - 导出方法未定义

转载 作者:行者123 更新时间:2023-11-30 19:54:57 24 4
gpt4 key购买 nike

我是 JavaScript 的新手,我遇到了一个问题,我试图从一个文件中调用一个函数,该文件也被导出。我该如何调用这个函数?重要的是我能够从此文件中调用此函数以及将其导出以供其他用途。非常感谢您的帮助!

我在下面添加了相关代码:

module.exports.handleCreatedTs = function(criteria, newSearch){  
...Lots of Calculations happen here...
}

module.exports.handleDateAndTermsDueDate = function(criteria, newSearch, isTermsDueDate){
var tempSearchObj = {};
handleCreatedTs(criteria, tempSearchObj); //This is where the exception is thrown

if(isTermsDueDate){
newSearch.termsDueDate = tempSearchObj;
}
else{
newSearch.date = tempSearchObj;
}
}

module.exports.handleInvoiceSupplierName = function(criteria, newSearch){
if(criteria.operator != "equals"){
return; //Not going to handle this
}

newSearch.supplierOrg.push({text: criteria.value, value: criteria.value});
}

最佳答案

您的代码 handleCreatedTs() 中没有变量。您有一个分配给 module.exports.handleCreatedTs() 的匿名函数。

可以使用 module.exports.handleCreatedTs() 调用它,但首先定义命名函数并将其添加到 module.exports< 可能更清晰 如果您计划从模块中调用它。

function handleCreatedTs(criteria, newSearch){  
// ...Lots of Calculations happen here...
}

// you can call handleCreatedTs()

// export the function:
module.exports.handleCreatedTs = handleCreatedTs

关于javascript - 导出方法未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54096488/

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