Javascript setInterval and `this` solution

前端 未结 9 2026
花落未央
花落未央 2020-11-22 08:44

I need to access this from my setInterval handler

prefs: null,
startup : function()
    {
        // init prefs
        ...
                


        
9条回答
  •  野性不改
    2020-11-22 09:26

    That's not a beauty solution but it's in common usage:

    var self = this;
    var ajax = null;
    //...
    ajax.onload = function() {
        self.prefs....;
    }
    

提交回复
热议问题