0
underscore.debounce()を動作させるのに問題があります。私は、入力フィールドにkeydownイベントリスナーを付けています。いくつかのアクションを実行し、呼び出されていないdebounce()を呼び出します。なぜそれが動作していないのだろうか?_.debounce()を動作させることができません
私は2つのサンプルを提供しました。私が_.debounce()
をインラインで添付していない最初のものは機能しません。私が_.debounce()
をインラインで添付している2番目のものが動作しています。非インラインソリューションがなぜ機能しているのか理解できません。
// This example does not ever call _.debounce()
$('input').on('keydown', onKeyDown);
function onKeyDown() {
console.log('performing some actions...');
_.debounce(function() {
console.log('debouncing'); // never called
}, 500);
}
// This example does call _.debounce()
$('input').on('keydown', _.debounce(function() {
console.log('debounce');
}, 500));
恐ろしい、ありがとう:) – Jon