js兼容低版本globalThis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<script>
if (typeof globalThis === 'undefined') {
if (typeof window !== 'undefined') {
window.globalThis = window;
} else if (typeof self !== 'undefined') {
self.globalThis = self;
} else if (typeof global !== 'undefined') {
global.globalThis = global;
} else {
// 注意:在严格模式下,这将在全局范围内定义一个全局变量
this.globalThis = this;
}
}
</script>