Debouncing
is a method of preventing a function from being invoked too often, and instead of waiting a certain amount of time until it was last called before invoking it. A great example of where this is useful is an auto-completing input field that calls an API with the partial input to get a list of possible complete inputs.
https://algochurn-server.onrender.com/practice/countries/:country
API is called.Request:
https://algochurn-server.onrender.com/practice/countries/ind
Response:
{
countries: ["British Indian Ocean Territory",
"India",
"Indonesia"
]
}
Click to reveal
You'll need setTimeout()
to create a debounce function.
Click to reveal
Can you use callback functions along with .call()
.apply()
and .bind()
to make this code work?