1. var getGlobal = function () {
    2. if (typeof self !== "undefined") {
    3. return self;
    4. }
    5. if (typeof window !== "undefined") {
    6. return window;
    7. }
    8. if (typeof global !== "undefined") {
    9. return global;
    10. }
    11. throw new Error("unable to locate global object");
    12. };
    13. var globals = getGlobal();
    14. if (typeof globals.setTimeout !== "function") {
    15. // 此环境中没有 setTimeout 方法!
    16. }

    globalThis