UNPKG
js-util-libsjia
Version:
latest (1.0.0)
1.2.7
1.0.0
jiahui的js常见的函数工具库
github.com/fuzhaoyang/js-util-libs.git
fuzhaoyang/js-util-libs
js-util-libsjia
/
src
/
throttle_debounce
/
index.js
12 lines
(11 loc)
•
279 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
// 时间戳写法
export
default
function
throttled1
(
fn, delay =
500
) {
let
oldtime =
Date
.
now
();
return
function
(
...args
) {
let
newTime =
Date
.
now
();
if
(newTime - oldtime >= delay) { fn.
apply
(
null
, args); oldtime =
Date
.
now
(); } }; }