我有一个.js文件如下:
module.exports = {
metadata: () => ({
"name": "HrScheduleApi",
"properties": {
"scheduleDate": {"type": "string", "required": false}
}
}),
invoke: (conversation, done) => {
var actionType = conversation.properties().actionType;
logger.info("start of HrScheduleApi with action type:" + actionType);
if(isBeyondThreeDays(scheduleDate) == false){
dayFromNow = '2 days from now';
var tomorrow = new Date(new Date().getTime() + 48 * 60 * 60 * 1000);
schDate = tomorrow.toDateString();
}else{
console.log('asked schedule is beyond 48 hours');
}
},
isBeyondThreeDays: (scheduleDate) => {
// ...
}
};
所以当我在我的调用函数中需要一个新函数(isBeyondThreeDays)时,我刚刚定义如下。但似乎nodejs不喜欢它。我收到了错误 在运行时间:
Error in component, details={}
ReferenceError: isBeyondThreeDays is not defined
答案 0 :(得分:1)
我猜这个
if(isBeyondThreeDays(scheduleDate) == false){
应该是
if(module.exports.isBeyondThreeDays(scheduleDate) == false){
或者
const myModule = { ... your methods}
和
if(myModule.isBeyondThreeDays(scheduleDate) == false){
...
module.exports = myModule