美文网首页
this指向

this指向

作者: Artifacts | 来源:发表于2019-08-21 21:54 被阅读0次

1.在全局使用this

  console.log(this)//this指向window

2.函数中的this

  function show(){
    consloe.log(this);//window,谁调用,this就指向谁
  }
show()

3.事件绑定中的this

  var box = document.querySelector(".box")
          box.onclick = function(){
                console.log(this);  //box, 谁绑定事件,this就是谁
          }
  1. 事件绑定中,调用其它函数的this
   var box = document.querySelector(".box")
             function show(){
                 console.log(this);  //window,谁调用,this是谁
             }
             box.onclick = function () {
                console.log(this); //this指向box
                 show();
             }

5.定时器中的this: 无论定时器在哪出现,其内部的this都指window

  setInterval(function(){
                     console.log(this) //window
                 },3000)
  1. 构造函数和原型中的this
  //this指向new出来的新的实例化对象

改变this指向

相关文章

  • this指向以及改变this指向

    改变this指向 call() apply() bind()

  • this指向

    this指向: 简单的一句话,谁调用的函数,this就指向谁 例子: var obj = { fun1: func...

  • this指向

    axios.get('/api', {params: {name: "kerwin",age:100}}).the...

  • this指向

  • this指向

    例 例

  • this 指向

    window.name = 'xiaoyu' var myObj = {name: 'seven',getName...

  • 指向

    平静的海托着翻飞的火焰,离开港口就有多少离人的泪还会再次上演,看着手上的钟表计算着离开的航线,肃穆的夜还有一串星火...

  • this 指向

    this执行全局环境中 this 指向 window this很重要的解析 https://segmentfaul...

  • this指向

    // 在普通函数中,函数的调用者是window对象,所以函数中的this指针指向的是window,通过访问this...

  • 指向

    飘飘荡荡,所有的事情都在直指一个方向 珍惜所有的付出,不在一处能回馈的也必会找到另一种方式。愿长长久久

网友评论

      本文标题:this指向

      本文链接:https://www.haomeiwen.com/subject/neusaqtx.html