From 64177d4675d15c247a98ce87916dec1c782f61e9 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 16 Sep 2019 15:02:38 +0800 Subject: [PATCH] fix(globalThis): fix ReferenceError ReferenceError: self is not defined #308 --- packages/utils/src/globalThis.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/globalThis.ts b/packages/utils/src/globalThis.ts index 31378c5dee0..99af5ea3b72 100644 --- a/packages/utils/src/globalThis.ts +++ b/packages/utils/src/globalThis.ts @@ -1,2 +1,13 @@ -export const globalThisPolyfill = - self || window || global || Function('return this')() +function globalThis() { + if (typeof self !== 'undefined') { + return self + } + if (typeof window !== 'undefined') { + return window + } + if (typeof global !== 'undefined') { + return global + } + return Function('return this')() +} +export const globalThisPolyfill = globalThis()