When I use major communities to check knowledge about Angular, I often see two modes of dependency injection, some of which are controller.('Ctr',[$scope,function($scope){...}] );
Some are directly controller.('Ctr',function($scope){...});
I would like to ask if this latter mode is new and universal?
The best practice is to use: controller.('Ctr',['$scope',function($scope){...}]).
As @Deboy said, for js compression.
Better performance. (controller.('Ctr',function($scope){...}), angularjs will parse the parameters of this function, and finally get the content to be injected, while the array-style writing method can skip the parsing step, and the performance will be better). Attached is the source code for reference:
Because in the process of front-end optimization, files such as js will be compressed and some strings will be replaced with single letters. If this is the case, angular injection will fail. The latter one is not processed to prevent injection after compression. The previous one did this, so even if it is compressed, it will not cause the injection to fail
The effects of the two executions during the development phase are the same
angular
的依赖注入的实现方式,没有什么规范/标准可谈,但却是不错的思路。我之前写过一篇教程,教你手写一个类似
angular
’s dependency injection system, I hope it will be useful to you: BDD handwritten dependency injection