Package Exports
- lw-utils-package
- lw-utils-package/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lw-utils-package) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
防抖函数
"效果" :单位时间内多次触发,只执行最后一次
// 参数1传入一个回调函数,参数2传入防抖生效时间
function debounce(callback, delay) {
let timer = null;
return function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
callback.apply(this, args);
}, delay)
}
}
节流函数
单位时间内只响应一次触发
// 参数1传入一个回调函数,参数2传入节流单位时间
function throttle(callback, delay) {
let timer = null;
return function (...args) {
if (timer) return;
timer = setTimeout(() => {
callback.apply(this, args);
timer = null;
}, delay)
}
}
深克隆
作用:完整复制一个对象,与源对象不会发生内存共享
// 传入需要克隆的对象,返回一个新对象
function deepClone(target)