s_baklanov,
ввести текст, подождать 2сек.
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
/*https://github.com/Kolyaj/CrossJS/blob/master/source/lang/Function.js#L26 */
(function(Function_prototype) {
Function_prototype.debounce = function(delay, ctx) {
var fn = this, timer;
return function() {
var args = arguments, that = this;
clearTimeout(timer);
timer = setTimeout(function() {
fn.apply(ctx || that, args);
}, delay);
};
};
})(Function.prototype);
window.addEventListener('DOMContentLoaded', function() {
var input = document.querySelector('input');
function test() {
alert(this.value);
}
input.addEventListener('input', test.debounce(2000));
});
</script>
</head>
<body>
<input name="">
</body>
</html>