Home  >  Article  >  Web Front-end  >  Usage examples of unref() and ref() for setTimeout and setInterval in javascript_javascript tips

Usage examples of unref() and ref() for setTimeout and setInterval in javascript_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:30:242086browse

The usage of unref() and ref() is very simple, they are to cancel and reply to the calls of setTimeout and setInterval functions.

The code is as follows:

Copy code The code is as follows:

var testFunction=function(){
console.log("guoyansi");
}
var timer=setInterval(testFunction,1000);
timer.unref();//Cancel the call of setTimeout and setInterval functions
timer.ref();//Restore the calls to setTimeout and setInterval functions

Isn’t it super simple? If you still don’t understand, please let go of javascript~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn