Error when the function is call

insed the function pomadoroTime(), there are other function and the function this.start() start the clock and when the time over I call this.fivePause() that start the 5 minutes pomadoro pause, but I got a error saying that the function this.fivePause()` doens’t exist. What am I doing wrong?

setInterval changes the execution context of your function, meaning this no longer references your timer object but the window object instead. The easiest way to fix this is with ES6 arrow functions, but you can also just cache a reference to this within a closure.

test = (function() {
    var self = this; //use self anywhere you'd use this
    return setInterval(function() {
        // ... stuff
})() // this is an IIFE, or immediately invoked function expression.  It's a function that runs immediately, natch.
1 Like