笔记
文章目录
1、创建26个大写字母
const alphabet = Array.from(new Array(26), (ele, index) => {
return String.fromCharCode(65 + index);
});2、获取当前时间戳
const now = +new Date();3、防抖节流
防抖(debounce):某一时间段内只执行一次,多应用于search搜索联想,Window触发
resize事件
节流(throttle):间隔时间执行,多应用于鼠标不断点击mousedown,监听滚轮事件
function debounce(fn, delay) {
let timer = null;
return function () {
let that = this;
let _args = arguments;
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(function() {
fn.call(that, _args)
}, delay)
}
}
function throttle(fn, delay) {
let prev = +new Date();
return function() {
let that = this;
let _args = arguments;
let now = +new Date();
if(now - prev >= delay) {
fn.call(that, _args);
prev = +new Date();
}
}
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论