From 1d54103012f4d85cb397d0510f1cf2ed3dbdbc51 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Mar 2023 06:48:52 +0800 Subject: [PATCH] refactor: ts debounce fn --- lib/hexo/index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index eb041289e2..63d3a77070 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -93,14 +93,12 @@ const createLoadThemeRoute = function(generatorResult, locals, ctx) { }; }; -function debounce(func, wait) { - let timeout; +function debounce(func: () => void, wait: number) { + let timeout: NodeJS.Timeout; return function() { - const context = this; - const args = arguments; clearTimeout(timeout); timeout = setTimeout(() => { - func.apply(context, args); + func.apply(this); }, wait); }; }