028-86922220

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

关于 js 的 this 指向问题

一、复杂度

二、影响 this 指向的因素

三、经验性的概括

  1. 普通函数的 this 指向,只和调用方式有关
  2. 箭头函数的 this 指向,只和定义环境有关

四、举例说明

  1. 改变普通函数的调用者
     1 <script>
     2     // 定义一个方法
     3     const person= {
     4         getInfo() {
     5             console.log(this);
     6         },
     7     };
     8     // 把方法拿出来,定义一个顶级变量
     9     const getInfo= person.getInfo;
    10 
    11     person.getInfo();// 调用者:person,this:person
    12     getInfo();// 调用者:window,this:window
    13 script>

    标题名称:关于 js 的 this 指向问题
    新闻来源:http://www.tsicrk.com/article/dsojico.html

其他资讯

让你的专属顾问为你服务

1.1290s