将角控制器/服务/工厂声明包装在匿名函数中的好处是什么? [英] What is the benefit of wrapping angular controller/service/factory declarations in an anonymous function
本文介绍了将角控制器/服务/工厂声明包装在匿名函数中的好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经看到一些开发人员在匿名函数中封装有角度的组件时兜售最佳实践。例如:
I've seen a few developers tout 'best practices' when wrapping angular components in anonymous functions. For example:
(function(){
angular.controller('MyCtrl', [function(){
// ... controller logic
}]);
})()
如果在所有任何方面,在匿名函数中包装angularjs组件的好处是什么?
What is the benefit of wrapping angularjs components in anonymous functions, if at all any?
推荐答案
立即调用函数。
(function(){
})()
上面将声明一个将被立即调用的匿名函数。
The above will declare an anonymous function that will be called immediately.
这篇关于将角控制器/服务/工厂声明包装在匿名函数中的好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文