I am making something like this:
var talkAPI = {
init: function(){
setInterval(function(){
this.speak();
},1000);
},
speak: function(){
//Something else
}
};
However, I found this is not working as I expected. So I did some tests, and I found out that this in the setInterval is referring to the Window. And this is not I wanted. So how can I re-refer this to talkAPI? Because I don’t want to do this:
setInterval(function(){
window.talkAPI.speak(); //Not so good
},1000);
You need to save the original
thisfor use in the callback