I'm currently utilizing TypeScript to create classes using the Dependency Injection design pattern. In the code of the Injector class, there is a particular line that stands out: car.apply(car, [new doors]). The expectation is that by executing the main class, we should be able to use the injected dependencies and methods as arguments. However, it appears that the .apply method does not actually execute the function as intended! So, what is truly happening here?
var car = function (){
function car(doorsClass){
this.doorsClass = doorsClass;
this.color('red');
this.doorsNum(4);
}
car.prototype.color = function(color){
console.log('Car color is '+color);
}
car.prototype.doorsNum = function(doorsNum){
console.log('Car has '+this.doorsClass.doors(doorsNum)+' doors');
}
return car;
}
var doors = function (){
function doors(){ }
doors.prototype.doors = function(num){
return num;
}
return doors;
}
car.apply(car, [new doors]);