A more advanced technique is to use a dependency injection library, such as Autofac for C#, Spring for Java, or Inversify for TypeScript. When using a DI container, the container is responsible for filling references in constructors with the appropriate values.
An example in TypeScript using Inversify:
let container = new Container();
container.bind<GlobalObject>().to(GlobalObject).inSingletonScope();
@injectable()
class InstanceObject {
constructor(@inject(GlobalObject) globalObject) {
}
}
let instance1 = container.get<InstanceObject>();
let instance2 = container.get<InstanceObject>();
At the end the code will have constructed two new objects, instance1 and instance2, which both have references to the global object without needing to be manually wired up.
This is a simple case for which dependency injection is overkill, but with larger applications, DI becomes indispensable.