Javascript setInterval and `this` solution
问题 I need to access this from my setInterval handler prefs: null, startup : function() { // init prefs ... this.retrieve_rate(); this.intervalID = setInterval(this.retrieve_rate, this.INTERVAL); }, retrieve_rate : function() { var ajax = null; ajax = new XMLHttpRequest(); ajax.open(\'GET\', \'http://xyz.com\', true); ajax.onload = function() { // access prefs here } } How can I access this.prefs in ajax.onload ? 回答1: The setInterval line should look like this:- this.intervalID = setInterval(