How to run a function once when binding to multiple events that all trigger in Javascript?
问题 I have a search input that listens to keyup and change to trigger an update of a listview via Ajax. Looks like this: input.on('keyup change', function(e) { if (timer) { window.clearTimeout(timer); } timer = window.setTimeout( function() { timer = null; val = input.val(); el = input.closest('ul'); // run a function - triggers Ajax widget[func](dyn, el, lib_template, locale, val, "update"); }, interval ); }); All working nice, except the handling of the timeout and binding, which causes double