我正在编写代码来对api中的某些资源执行“监视”: 考虑我的代码:
function myObj(){
this.endpoint = "/example"; // my endpoint
this.interval = 500; // my watch interval
}
myObj.prototype.watch = function(){
console.log(this.endpoint); // returns "/example"
this.intervalId = setInterval(this.refresh, this.interval);
}
myObj.prototype.destroy= function(){
clearInterval(this.intervalId);
}
myObj.prototype.refresh = function(){
console.log(this.endpoint) // -> undefined ???
}