first commit
This commit is contained in:
20
code/SmallCart/SmallCartMain/data/js/utils.js
Normal file
20
code/SmallCart/SmallCartMain/data/js/utils.js
Normal file
@@ -0,0 +1,20 @@
|
||||
class Utils {
|
||||
$(className) {
|
||||
return document.querySelector(className);
|
||||
}
|
||||
|
||||
|
||||
debounce(fn, delay = 1000) {
|
||||
let timer = null //借助闭包
|
||||
return function () {
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(fn, delay) // 简化写法
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var { $, debounce } = new Utils();
|
||||
Reference in New Issue
Block a user