function classFactory() { return class Foo { #foo = "foo"; static #bar = "bar"; instance() { return this.#foo; } static() { return Foo.#bar; } static instance(inst) { return inst.#foo; } static static() { return Foo.#bar; } }; } const Foo1 = classFactory(); const Foo2 = classFactory(); const f1 = new Foo1(); const f2 = new Foo2(); expect(f1.instance()).toBe("foo"); expect(f1.static()).toBe("bar"); expect(f2.instance()).toBe("foo"); expect(f2.static()).toBe("bar"); expect(Foo1.instance(f1)).toBe("foo"); expect(Foo1.static()).toBe("bar"); expect(Foo2.instance(f2)).toBe("foo"); expect(Foo2.static()).toBe("bar"); expect(() => { f1.instance.call(f2), undefined; }).toThrow(); expect(() => { f2.instance.call(f1), undefined; }).toThrow(); expect(() => { Foo1.instance(f2), undefined; }).toThrow(); expect(() => { Foo2.instance(f1), undefined; }).toThrow();