From f0c7c42d516f26679ca80de4336bca87aa65e0b2 Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Thu, 18 Jul 2019 16:18:15 +0100 Subject: [PATCH] feat: add globalThis polyfill --- src/globalthis.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/globalthis.js diff --git a/src/globalthis.js b/src/globalthis.js new file mode 100644 index 0000000..6e56a77 --- /dev/null +++ b/src/globalthis.js @@ -0,0 +1,20 @@ +/* eslint-disable no-undef */ +/* eslint-disable no-extend-native */ +/* eslint-disable strict */ + +// polyfill for globalThis +// https://v8.dev/features/globalthis +// https://mathiasbynens.be/notes/globalthis +(function () { + if (typeof globalThis === 'object') return + Object.defineProperty(Object.prototype, '__magic__', { + get: function () { + return this + }, + configurable: true + }) + __magic__.globalThis = __magic__ + delete Object.prototype.__magic__ +}()) + +module.exports = globalThis