Avatar of Rohit Bajaj
Rohit Bajaj
Flag for India

asked on 

setting timer on a function in javascript/jquery

I have the following piece of code  :
var timeoutid = undefined;
cm.on(“changes”, function() {
    if(timeoutid !== undefined) {
       timeoutid = undefined
       timeoutid = window.setTimeout(detect,500);

Open in new window

Here cm refers to an editor... and whenver user types in .on('changes') will get called..
what i wanted to achieve is execute a function detect only when user halts for a typing.

For this i have used setTimeout();
This is the first time i am using such a function. Want to know if there are any alternatives better way to achieve the same. are there any pros or cons of using the way i am doing it ?


Avatar of undefined
Last Comment

8/22/2022 - Mon