Debounce doesn't work with Searchbar

As you know when you use external API in Searchbar, you will need to reduce API calls, to do that i tried debounce but it didn’t work, i don’t know why.
This is a simple example i made https://jsfiddle.net/Lhuqxn6p/, try to comment $$("#searchT").append(query+" <br />");
and uncomment the debounce function to see what i mean.

later() is never called and timestamp is nowhere defined…

I tried everything i could find, it’s not working. this is the closest thing i got: https://jsfiddle.net/Lhuqxn6p/, but it’s not working the proper way, after you type it wait for that amount of milliseconds, but it execute the function 10 times if you enter 10 chars. i mean we do the whole debounce thing to prevent calling a function many times, like to wait for 1 seconds then call it once, not to wait 1 seconds then call it 10 successive times.

Your debounce function is wrong and doesn’t actually do any debounce. In my apps i use simple timeout thing which is usually enough for 99% of use cases https://jsfiddle.net/j92ugqzf/

I don’t know how i didn’t thought about it this way. thanks a lot