前言

全局 this

⭐️ 获取全局对象 this

web

var a = 1;
var b = function() { console.log('fun b中的this:', this) }
c = {};
console.log('this === window', this === window);
console.log('window.a === a:', window.a === a);
b();
console.log('window.c === this.c:', window.c === this.c);

Untitled

严格模式下:

"use strict";
c = 123;

Untitled

"use strict";
var b = function() { console.log('fun b中的this:', this) }
b();