File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
1-js/06-advanced-functions/09-call-apply-decorators/04-throttle Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ function throttle(func, ms) {
3232调用 ` throttle(func, ms) ` 返回 ` wrapper ` 。
3333
34341 . 在第一次调用期间,` wrapper ` 只运行 ` func ` 并设置冷却状态(` isThrottled = true ` )。
35- 2 . 在这种状态下,所有调用都记忆在 ` savedArgs/savedThis ` 中。请注意,上下文和参数( arguments)同等重要,应该被记下来。我们同时需要他们以重现调用 。
36- 3 . ……然后经过 ` ms ` 毫秒后,触发 ` setTimeout ` 。冷却状态被移除(` isThrottled = false ` ),如果我们忽略了调用,则将使用最后记忆的参数和上下文执行 ` wrapper ` 。
35+ 2 . 在冷却状态下,所有调用都被保存在 ` savedArgs/savedThis ` 中。请注意,上下文(this)和参数( arguments)都很重要,应该被保存下来。我们需要它们来重现调用 。
36+ 3 . 经过 ` ms ` 毫秒后,` setTimeout ` 中的函数被触发 。冷却状态被移除(` isThrottled = false ` ),如果存在被忽略的调用,将使用最后一次调用保存的参数和上下文运行 ` wrapper ` 。
3737
38- 第 3 步运行的不是 ` func ` ,而是 ` wrapper ` ,因为我们不仅需要执行 ` func ` ,还需要再次进入冷却状态并设置 timeout 以重置它 。
38+ 第 3 步运行的不是 ` func ` ,而是 ` wrapper ` ,因为我们不仅需要执行 ` func ` ,还需要再次进入冷却状态并设置 ` setTimeout ` 以重置节流 。
You can’t perform that action at this time.
0 commit comments