Could anyone help with explaining why property of object refreshed by setInterval()
isn't accessible by a standalone function but only when the function is also called with setInterval()
?
Example below:
function a() {
return {
debug: aVariable,
};
}
let obj;
function objUpdate() {
obj = a();
}
setInterval(objUpdate, 1000);
function b() {console.log(obj.debug);}
///returns value of aVariable:
setInterval(b, 1000);
//doesn't return value of aVariable:
b();
Thank you in advance!