Skip to content
New issue

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

debounce #1

Open
caiyongqi opened this issue Jan 31, 2020 · 0 comments
Open

debounce #1

caiyongqi opened this issue Jan 31, 2020 · 0 comments

Comments

@caiyongqi
Copy link

caiyongqi commented Jan 31, 2020

防抖函数debounce在setTimeout中通过apply执行的函数(debounce第一个参数)中的this(apply第一个参数)测试为undefined,感觉应该在debounce中传入一个'this'(项目中为this.$refs.scroll)
// 防抖函数 export function debounce(func, that = null, delay = 500) { // 回调函数,和回调函数要执行须等待的时间ms let timer = null // this => Vue组件 return function (...args) { // this => undefined if (timer) { clearTimeout(timer) } timer = setTimeout(() => { // 测试证明此处使用this => undefined func.apply(that, args) //func() }, delay) } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant