GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javascript.info — Debounce decorator back to the lesson Debounce decoratorimportance: 5 The result of In other words, For instance, we had a function Then if the wrapped function is called at 0ms, 200ms and 500ms, and then there are no calls, then the actual …And it will get the arguments of the very last call, other calls are ignored. Here’s the code for it (uses the debounce decorator from the Lodash library):
Now a practical example. Let’s say, the user types something, and we’d like to send a request to the server when the input is finished. There’s no point in sending the request for every character typed. Instead we’d like to wait, and then process the whole result. In a web-browser, we can setup an event handler – a function that’s called on every change of an input field. Normally, an event handler is called very often, for every typed key. But if we In this live example, the handler puts the result into a box below, try it: See? The second input calls the debounced function, so its content is processed after 1000ms from the last input. So, It waits the given time after the last call, and then runs its function, that can process the result. The task is to implement Hint: that’s just a few lines if you think about it :)
A call to |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |