From 9efc90a658b9ff76477e0c1f25dc011e0ec792d5 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 17 Sep 2019 09:54:21 +0800 Subject: [PATCH] fix(globalThis): fix ReferenceError (#309) 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()