标签归档:闭包

JS 匿名函数与闭包的this指向

匿名函数与闭包的 this 均指向 window。

function a() {
  (function () {
    console.log(this, 'function');
  })();
  function b() {
    console.log(this, 'function b')
  };
  b();
}
a();
// > Window {window: Window, self: Window, document: document, name: '', location: Location, …} 'function'
// > Window {window: Window, self: Window, document: document, name: '', location: Location, …} 'function b'

继续阅读

发表在 JavaScript | 标签为 , , , , | JS 匿名函数与闭包的this指向已关闭评论