且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

告诉JS代码每次调用它只能运行一次?

更新时间:2023-02-25 15:13:44

在JavaScript中,几乎与任何语言一样(我能想到)没有例外,无论如何),每次调用只调用一次函数。如果你有一个无限循环,那么你有一个不同的问题。



你发布的任何内容都包含任何类型的循环(for,while,foreach)所以代码你发布的内容包含在一个循环中,你调用的代码(queueForceAction)包含一个被锁定的循环,或者你的某个地方有一个递归调用。



JS中的一个很好的故障排除技术是将console.log()语句塞进代码段,以帮助您诊断存在问题的位置。
In JavaScript, like pretty much any language (I can think of no exceptions, at any rate), a function is invoked only once for each call. If you have an infinite loop, then you have a different issue.

Nothing you posted includes a loop of any sort (for, while, foreach) so either the code you posted is contained in a loop, there code you call (queueForceAction) contains a loop that is getting locked, or you have a recursive call tucked in there somewhere.

One good troubleshooting techniques in JS is to tuck console.log() statements into sections of code to help you diagnose where issues exist.