We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
测试将immediate置为false,后面的函数变量没有被保存
immediate置为false
测试用例:
function testFn(name){ console.log(`hello ${name}`); } var d = debounce(testFn,0,false); d('xiaomin'); d('xiaohua'); -----> hello xiaomin // 置为false,应该输出 hello xiaohua
稍加修改
return function(...params) { // 否则缓存参数和调用上下文 // 更改的地方 context = this args = params // 如果没有创建延迟执行函数(later),就创建一个 if (!timer) { timer = later() // 如果是立即执行,调用函数 if (immediate) { func.apply(this, params) } // 如果已有延迟执行函数(later),调用的时候清除原来的并重新设定一个 // 这样做延迟函数会重新计时 } else { clearTimeout(timer) timer = later() } } // 测试用例输出 -----> hello xiaohua
The text was updated successfully, but these errors were encountered:
No branches or pull requests
测试将
immediate置为false
,后面的函数变量没有被保存测试用例:
稍加修改
The text was updated successfully, but these errors were encountered: