JS特性:this

关于 JavaScript 中不同地方的 this 指向。

本文中所有 Demo 均在 RunJS 中运行。

函数对象本身

当函数作为构造器被调用时,this 指向自身。

function constructor(){
  console.log(this);
}

new constructor();

箭头函数不能作为构造器

const arrowCanNotBeConstructor = () => {
  console.log(this);
}

new arrowCanNotBeConstructor();
// TypeError: arrowCanNotBeConstructor is not a constructor

JS特性:this

/note.js/u4qdco2f/
作者
0xarch
发布时间
许可协议
CC-BY-NC-SA 4.0