且构网

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

在重新开始之前等待功能完成

更新时间:2021-11-01 21:18:52

由于函数是对象,因此它们可以存储属性。你可以让函数在每次调用(按下按钮)时自动增加一个'queue'属性,然后在函数执行结束时,检查它自己的队列属性是否> 0,如果是,则减少队列属性一个并使用 setTimeout 再次调用自己。

Since Functions are objects they can store properties. You can have your function increment a 'queue' property on itself every time its called (button pressed) and then at the end of the function execution, check if the queue property of itself is > 0, and if so, decrement the queue property by one and call itself again using setTimeout.