函数节流
重复触发函数,执行第一次,n秒没有触发,就执行下一次
- 用途:防止重复点击提交按钮
function throttle(fn,n){
let timer = null;
return function(...args){
if(timer) return;
timer = setTimeOut(()=>{
fn.call(this,...args)
timer = null;
},n)
}
}
函数防抖
重复触发函数,执行最后一次
- 用途:屏幕滚动onScroll
function debounce(fn,n){
let timer = null;
return function(...args){
clearTimeOut(timer)
timer = setTimeOut(()=>{
fn.call(this,...args)
},n)
}
}
es6 模块导入导出
// 1
export const xxx = xxxx;
export cosnt xxx1 = xxx1;
import { xxx,xxx1 } from './';
// 2
export default xxx;
import xxx from './'
import xxx as jjj from './'
// 3
export * from './'
// 4
// 异步加载组件
const btn = document.createElement('button');
btn.innerHTML = '按钮'
btn.addEventListenr('click',function(){
import('./').then(res=>{
console.log(res.default)
})
})