Dependency injection in JavaScript