4
JavaScript 防抖函数,绑定事件后事件对象传参问题
source link: https://www.v2ex.com/t/879440
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
明明事件对象 e 是作为的 debounce 中的第一个 fn 函数参数,为什么能够被 debounce 函数返回的匿名函数中 的...args 获取得到呢?实在想不通,不知道有哪位同学可以答疑解惑,不胜感激
// 防抖
function debounce(func, wait = 500) {
let timeID;
return function (...args) {
if (timeID) clearTimeout(timeID);
timeID = setTimeout(() => {
func.apply(this, args);
}, wait);
}
}
let password = document.querySelector('[name="password"]');
// 明明事件对象 e 是作为的 debounce 中的第一个 fn 函数参数,为什么能够被 debounce 函数返回的匿名函数中
// 的...args 获取得到呢?实在想不通,不知道有哪位同学可以答疑解惑,不胜感激
password.addEventListener("keyup", debounce(function (e) {
console.log(222)
}, 500));
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK