logoalt Hacker News

MobiusHorizonsyesterday at 8:36 PM0 repliesview on HN

it also talks about the global object not being a place to add properties. So how you might do `window.foo = ...` or `globalThis.foo = ...` to make something from the local context into a global object. in this dialect I guess you would have to reserve any global objects you wanted to set with a `var` and then set them by reference eg

    // global. initialized by SomeConstructor
    var fooInstance

    class SomeConstructor {
       constructor(...) {
          fooInstance = this;
       }
       static getInstance(...) {
          if (fooInstance != null) return fooInstance;
          return new SomeConstructor(...);
       }
    }