JavaScript Dependency injection