イベントで一部のコードの実行を延期したい。setTimeout標準関数とプラグイン debounce ( debounce へのリンク)の使用の違いは何ですか?
の例を次に示し setTimeoutます。
var timeout;
$(window).on("scroll", function() {
clearTimeout(timeout);
timeout = setTimeout(function() {
doSomethingFunction();
}, 500);
});
そして、ここに debounce の例があります:
$(window).on("scroll",
$.debounce(500, doSomethingFunction)
);
もちろん、デバウンスを使用するとコードは短くなりますが、他に利点はありますか? どちらが速くなりますか?