I havethe following exported object:
module.exports = {
value: 0,
startTimer: function() {
setInterval(function() {
value++;
}, 1000);
}
}
How can I access value from that setInterval function?
Thanks in advance.
You can either specify the full path to the value:
Or, if you bind the function called by
setTimeouttothis, you can usethis:This is similar to code like this, which you will see from time to time: