I am a beginner in angularjs, I start learning by their tutorial, but when comes to dependency injection, I am not quite understand what it means
function SomeClass(greeter) {
this.greeter = greeter;
}
SomeClass.prototype.doSomething = function(name) {
this.greeter.greet(name);
}
In the above example SomeClass is not concerned with creating or locating the greeter dependency, it is simply handed the greeter when it is instantiated.
This is desirable, but it puts the responsibility of getting hold of the dependency on the code that constructs SomeClass.
What actually does the bolded sentence mean?
"The code that construct SomeClass", does that mean the function SomeClass(greeter)?
Thanks all for the advice
var some = new SomeClass(greeterInstance). So the responsibility of this code is to provide propergreeterInstanceobject implementinggreeterinterface.greeterInstancedoesn't match the greeter interface (e.g. a greet method)some.doSomething()will throw an error. This tightly coupling is what DI solves.