Directly from the official @GitHub page:
The most basic method is to retrieve the dependencies from the arguments of the function. This involves converting the function into a string using the toString()
method and then extracting the argument names.
// Example
function MyController($scope, $route) {
// ...
}
// Outcome
expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
Concerning the annotate function
function annotate(fn) {
var $inject,
fnText,
argDecl,
last;
if (typeof fn == 'function') {
if (!($inject = fn.$inject)) {
$inject = [];
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg){
arg.replace(FN_ARG, function(all, underscore, name){
$inject.push(name);
});
});
fn.$inject = $inject;
}
} else if (isArray(fn)) {
last = fn.length - 1;
assertArgFn(fn[last], 'fn')
$inject = fn.slice(0, last);
} else {
assertArgFn(fn, 'fn', true);
}
return $inject;
}
found on line 45 onwards