I have normally learned that function implementation can have any name for function arguments as long as it is supplied in the right order. This makes the function abstracted from the outside world and the local names have no effect on the output . Implementer has all the rights for local variables. However in Angular JS, it seems to counter intuitive to have something like:
function Controller($scope)
{
$scope.name = "Something";
}
If I put "bar" there instead "$scope" I get an error. This is not the normal function that we are used to . I believe it something to do with DI, but can anyone explain this concept ? I find it hard to call this a "function" because it is dependent on the outside world - especially the argument name .
If DI is the real reason , can any one let me know how does it get invoked ? Normally I can think of DI doing good when I want to mock an object for test case. In this case what role does DI play ?
In the normal scenarios of DI that I have come across , the argument that gets passed, does a service for the function like say foo displayTime(clock) { clock.something } . Time is just a service for the the function . However here I find that , the $scope and the framework seems to do the magic with the function just being declarative way of expressing the logic .
Edit : Apparently JS minify breaks this functionality and we need to do like in How do the function argument names in Angular.js objects connect to other objects?