@ Already found the answer, but here is the explanation.
If you call the function as follows:
AS.popElement();
the popElement function is executed in the context of the AS object (the value "this" refers to AS). But if you use setInterval (or any callback function) as follows:
setInterval(AS.popElement, 1000);
you only pass a link to the popElement function. Therefore, when popElement is executed 1000 milliseconds later, it is executed in the global context (this means that "this" refers to the window). You will get the same error if you called:
window.popElement();
A possible alternative to this is to avoid the following:
setInterval(function() { return AS.popElement() }, 1000);
Another option would be to use the apply or call methods to explicitly indicate your context:
setInterval(AS.popElement.apply(AS), 1000);
source share