dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 58 forks source link

Accessing global #182

Closed kitsonk closed 8 years ago

kitsonk commented 8 years ago

It appears that in some environments, the global scope is not referencable via our current method:

const globalObject: any = Function('return this')();

In particular when some CSP restrictions are in place. There is a TC39 proposal to make it available and accessible in a consistent place and describes the issue.

We should consider changing this to:

const globalObject: any = function() {
    if (typeof self !== 'undefined') {
        return self;
    }
    if (typeof window !== 'undefined') {
        return window;
    }
    if (typeof global !== 'undefined') {
        return global;
    }
    throw new Error('unable to locate global object');
}();