AngularJS stores dependency names as strings, which makes sense, since we can do:
var dependencies = {};
function addDependency(name, value){
if (typeof name == 'string') {
dependencies['name'] = value;
} else {
//throw err
}
}
But I don't understand how it's possible to grasp that value through a non-string parameter the way AngularJS does, where it tells you in order to access dependencies, just treat parameters as names:
The simplest way to get hold of the dependencies is to assume that the function parameter names are the names of the dependencies.
someModule.controller('MyController', function($scope, greeter) { // ... });
In the abover case, I would think greeter
would have to be in the form of a string so it could be accessed in a loop like dependencies[argument[i]];
I just don't understand how it's possible in JavaScript to map that parameter's name to a certain dependency name if the argument isn't a string. How is this possible? I'd really like to know how to do this for various syntax improvements in my code.