Javascript setInterval and `this` solution

前端 未结 9 2025
花落未央
花落未央 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:08

    window.setInterval(function(){console.log(this)}.bind(this), 100)

    this is legal in javascript and saves lots of code :)

提交回复
热议问题