AngularJS:window.angular变量 [英] AngularJS : window.angular variable
问题描述
我正在寻找有关window.angular变量的信息,但没有发现期望
I was looking for informations to window.angular variable and i found nothing expect this post. In this post we have the following code :
(function(angular, undefined){
'use script';
var djng_forms_module = angular.module('ng.django.forms', []);
funtion hasCode(s){
return .....
}
var foo = .....
}(window.angular));
有人解释说,当我们使用此代码段时,它确保在填充变量 window.angular 之后执行该代码段.我不明白为什么使用此语法时不可能无法定义 window.angular ,您能向我解释为什么吗?
And a person explains that when we use this code fragment it ensures that it is executed after the population of the variable window.angular. I don't understand why it could not be possible that window.angular could be undefined when use this syntax, could you explain to me why please ?
先谢谢您了:)
推荐答案
与确保此处的角度无关.据我所知,该语法可以执行3件事:
It has nothing to do with ensuring angular is here. It's the syntax that, as I know, does 3 things:
- 允许Minifier更改局部作用域变量的名称
- 减少变量的访问时间,因为它是本地作用域的
- 如果有人会创建局部范围内的角度"变量,则可以确保通过显式使用window变量来使用全局变量
但是,由于IIFE被立即调用,根据其定义,它不能以任何方式确保window.angular的显示.
But since the IIFE is invoked immediately, according to it's definition, it doesn't ensure in any way that window.angular is presented.
这篇关于AngularJS:window.angular变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!