Since entering angular.js, I have seen a generic pattern related to callback arguments. An example is the ui-router documentation :
var myApp = angular.module('myApp', ['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider) {
}):
But due to the desire I saw, the callback arguments myApp.configmay be different, and it will still behave as expected:
myApp.config(function(OtherProvider) {
});
How myApp.configdoes it know the difference? Has a strange magical introspection occurred, or is there some basic JS concept that allows this? For instance. sort of:
myApp.config = function(callback) {
var providerNames = callback.argumentNames;
var providers = this.findProviders(providerNames);
};
Maybe I'm too accustomed to python, where such a function will be possible only with the help of some very scary hacks.
source
share