为什么我的功能无法被识别?的JavaScript

时间:2019-06-20 06:33:42

标签: javascript node.js socket.io

好的,所以我大大减少了代码,现在略有不同,但是它执行相同的操作。

game-socket.js

//Start Fight Action
socket.on("fight", () => {
 combat(io, socket, app);
});

action-timer.js

const combat = require("./combat/combat");
module.exports = (type, io, socket, app) => {
  if (type == "combat") {
    app.online.actionTime = setTimeout(() => {
      combat(io, socket, app);
    }, 1000);
  } else if (type == "tradeskill") {
  }
};

combat.js

const startAction = require("../action-timer");
module.exports = (io, socket, app) => {
  //Run another combat
  console.log("COMBAT");
  startAction("combat", io, socket, app);
};

错误:

action-timer.js:5
      combat(io, socket, app);
      ^

TypeError: combat is not a function
    at Timeout.app.online.actionTime.setTimeout [as _onTimeout] (C:\Users\wjpop\Desktop\kog\funcs\action-timer.js:5:7)
    at listOnTimeout (timers.js:327:15)
    at processTimers (timers.js:271:5)

1 个答案:

答案 0 :(得分:1)

我想出来了,很奇怪,我必须这样做,因为通常不需要这样做,但是action-timer.js应该像这样:

module.exports = (type, io, socket, app) => {
  const combat = require("./combat/combat");
  if (type == "combat") {
    app.online.actionTime = setTimeout(() => {
      combat(io, socket, app);
    }, 1000);
  } else if (type == "tradeskill") {
  }
};