Skip to content

Commit f0c7c42

Browse files
committed
feat: add globalThis polyfill
1 parent 0b8e6b8 commit f0c7c42

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/globalthis.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable no-undef */
2+
/* eslint-disable no-extend-native */
3+
/* eslint-disable strict */
4+
5+
// polyfill for globalThis
6+
// https://v8.dev/features/globalthis
7+
// https://mathiasbynens.be/notes/globalthis
8+
(function () {
9+
if (typeof globalThis === 'object') return
10+
Object.defineProperty(Object.prototype, '__magic__', {
11+
get: function () {
12+
return this
13+
},
14+
configurable: true
15+
})
16+
__magic__.globalThis = __magic__
17+
delete Object.prototype.__magic__
18+
}())
19+
20+
module.exports = globalThis

0 commit comments

Comments
 (0)