11-8 定时器this

定时器this问题  

  var t=setInterval(function(){

    console.log(this)

  },1000)

  这里面的thiswindow

  Person.prototype={

    fn:function(){

    console.log(this)

   },

  n:200,

  t:setInterval(this.fn,2000)

  }

  var ss=new Person("zhang")

不管定时器里函数怎么写它里面this都是window

怎么处理定时器中的this为指定的对象

在函数前面将关键字this赋值给一个变量,函数内使用这个变量代替this就可以了

这种了解一下。

原文地址:https://www.cnblogs.com/wwwzhaocom/p/10043872.html