Rohit Bajaj
asked on
setting timer on a function in javascript/jquery
Hi,
I have the following piece of code :
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 ?
Thanks
I have the following piece of code :
var timeoutid = undefined;
cm.on(“changes”, function() {
if(timeoutid !== undefined) {
clearTimeout(timeoutid);
timeoutid = undefined
}
if(…){
timeoutid = window.setTimeout(detect,500);
}
});
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 ?
Thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.