function debounce(fn, s) {
let timer;
return function() {
clearTimeout(timer);
let _this = this;
let args = arguments;
timer = setTimeout(() => {
return fn.apply(_this, args);
}, s)
}
}
window.onscroll = debounce(function() {
console.log(1);
}, 500)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<div style="background-color: lightblue; height: 200vh;"></div>
</body>
</html>