From 7552763be3880b14066f9af9e5af836a37c2c2b2 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 7 Jul 2016 11:19:16 +0200 Subject: [PATCH] Determine ol.global in a way that works in more environments --- externs/closure-compiler.js | 2 ++ src/ol/ol.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/externs/closure-compiler.js b/externs/closure-compiler.js index 7894661c23..6fee440810 100644 --- a/externs/closure-compiler.js +++ b/externs/closure-compiler.js @@ -15,3 +15,5 @@ * @see http://www.w3.org/TR/pointerevents/#the-touch-action-css-property */ CSSProperties.prototype.touchAction; + +var global; diff --git a/src/ol/ol.js b/src/ol/ol.js index 211d0198ff..85eef506d2 100644 --- a/src/ol/ol.js +++ b/src/ol/ol.js @@ -275,4 +275,13 @@ ol.inherits = function(childCtor, parentCtor) { ol.nullFunction = function() {}; -ol.global = Function('return this')(); +/** + * @see https://github.com/tc39/proposal-global + */ +if (typeof window !== 'undefined') { + ol.global = window; +} else if (typeof global !== 'undefined') { + ol.global = global; +} else if (typeof self !== 'undefined') { + ol.global = self; +}