ES6

1
(typeof window !== 'undefined' ? window : (typeof process === 'object' && typeof require === 'function' && typeof global === 'object')? global : this);
1
2
3
4
5
6
var getGlobal = function(){
if(typeof self !== 'undefined'){return self;}
if(typeof window !== 'undefined'){return window;}
if(typeof global !== 'undefined'){return global;}
throw new Error('无法定位全局对象');
};