hgiesel / closet

The Web Framework for Flashcards
https://closetengine.com
GNU General Public License v3.0
65 stars 6 forks source link

Undefined globalThis on some older browsers #84

Open Zkffkah opened 2 years ago

Zkffkah commented 2 years ago

undefined globalThis on some older android browsers. Similiar to this https://github.com/zxing-js/browser/pull/27/files issue, and similar code should fix the problem.

image

Zkffkah commented 2 years ago

Following is the little polyfill I'm using to fix it before it's fixed. Inject it using asset manager.

(function (Object) {
  typeof globalThis !== 'object' && (
    this ?
      confGlobalThis() :
      (Object.defineProperty(Object.prototype, '_confGlobalThis_', {
        configurable: true,
        get: confGlobalThis
      }), _confGlobalThis_)
  );
  function confGlobalThis() {
    this.globalThis = this;
    delete Object.prototype._confGlobalThis_;
  }
}(Object));