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();
}
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。