Skip to content

Node 中的 this 是谁?

文件中的 this 指向的是 module.exports,值是 {},因为 commonjs 中,所有代码写到文件中, 文件内部自带一个函数,这个函数执行的时候改变了 this。

js
console.log(this) // {}
js
function foo () {
  console.log(this) // global
}

foo()