settimeout nodejs code example
Example 1: settimeout node js
setTimeout(function () {
console.log("5 secondes");
}, 5000);
console.log("now");
Example 2: setinterval nodejs
setInterval(function () {
console.log("Every 5 secondes");
}, 5000);
console.log("now");
Example 3: javascript this in settimeout
function func() {
this.var = 5;
this.changeVar = function() {
setTimeout(() => { //Don't use function, use arrow function so 'this' refers to 'func' and not window
this.var = 10;
}, 1000);
}
}
var a = new func();
a.changeVar();