zoukankan      html  css  js  c++  java
  • 箭头函数不会修改this

    function Person () {
      this.name = 'little bear',
      this.age = 18
      setTimeout(()=>{
    	console.log(this
    )
    })
    }
    var a = new Person()
    

    setTimeout里的this代表new Person出来的对象

    function Person () {
      this.name = 'little bear',
      this.age = 18
      setTimeout(function(){
    	console.log(this
    )
    })
    }
    var a = new Person()
    

    setTimeout里的this代表window

    由于箭头函数不改变this,所以setTimeout里面的箭头函数this,不能改变

      

      

    学而不思则罔,思而不结则殆,结而不看,一事无成
  • 相关阅读:
    0523注册审核
    0520三级联动
    0519考试练习题
    0516ajax
    mysql 高级查询
    mysql
    HTML的格局与布局
    css样式表
    HTML表单
    HTML
  • 原文地址:https://www.cnblogs.com/windseek/p/8708496.html
Copyright © 2011-2022 走看看