什么是globalThis:
全局属性 globalThis 包含全局的 this 值,类似于全局对象(global object):
function canMakeHTTPRequest() {
return typeof globalThis.XMLHttpRequest === 'function';
}
console.log(canMakeHTTPRequest());
// expected output (in a browser): true在前端引入一些开源组件库时,在低版本浏览器中可能会出现globalThis is not defined的问题,在html头部增加如下代码即可解决:

!(function (t) {
function e() {
var e = this || self;
(e.globalThis = e), delete t.prototype._T_;
}
"object" != typeof globalThis &&
(this
? e()
: (t.defineProperty(t.prototype, "_T_", {
configurable: !0,
get: e,
}),
_T_));
})(Object);