While reading through documentation on AngularJS services, I've stumbled across example services written like:
myApp.service('fooGetter', ['$http', function($http) {
this.getFoo = function() {
// use $http to get some foo
}
}]);
where $http is injected to the service wrapper so it can be referenced from within the service instance that is created. What is the reason for array syntax that contains the list of parameters, which are then duplicated in the function parameters? I haven't been able to find a good explanation of the purpose of that, it's rules, and why it's necessary. The same service, written without that, like:
myApp.service('fooGetter', function($http) {
this.getFoo = function() {
// use $http to get some foo
}
});
seems to have a perfectly fine automagic reference to that variable.