admin管理员组文章数量:1294698
I'm trying to understand an angularjs file I need to use to integrate with Django, and it has a weird syntax I'm not familiar with (bear in mind I'm a junior dev, so this may be your bread and butter)...
It goes something like:
(function(angular, undefined){
'use script';
var djng_forms_module = angular.module('ng.django.forms', []);
funtion hasCode(s){
return .....
}
var foo = .....
}(window.angular));
I've seen this about the javascript concept of a window and it shows that the window
part is the top (?) level object the browser creates when it loads the page.
Running console.log(window.angular)
prints out a load of internal angular stuff. So I'm guessing that is the internal guts of AngularJS...?
But why this weird encapsulation as a function (something to do with JavaScript being a 'functional' language)?
The full script is here and I can't figure out why it uses window.angular
in this function definition (as opposed to the normal way of doing things). It seems like this set up means it's not working for my application when I import it via script
tags.
I'm trying to understand an angularjs file I need to use to integrate with Django, and it has a weird syntax I'm not familiar with (bear in mind I'm a junior dev, so this may be your bread and butter)...
It goes something like:
(function(angular, undefined){
'use script';
var djng_forms_module = angular.module('ng.django.forms', []);
funtion hasCode(s){
return .....
}
var foo = .....
}(window.angular));
I've seen this about the javascript concept of a window and it shows that the window
part is the top (?) level object the browser creates when it loads the page.
Running console.log(window.angular)
prints out a load of internal angular stuff. So I'm guessing that is the internal guts of AngularJS...?
But why this weird encapsulation as a function (something to do with JavaScript being a 'functional' language)?
The full script is here and I can't figure out why it uses window.angular
in this function definition (as opposed to the normal way of doing things). It seems like this set up means it's not working for my application when I import it via script
tags.
1 Answer
Reset to default 8window.angular
is the global angularjs variable which is created once angularjs has been fully loaded from a script tag. The code fragment you have pasted ensures that it is executed after the population of this variable. One reason it might be written in that verbose way is simply its auto-generated nature. In a wider context, it may have implication to the order in which scripts are executed or to using different versions of the angularjs library.
本文标签: javascriptWhy is 39windowangular39 used like soin this function definitionStack Overflow
版权声明:本文标题:javascript - Why is 'window.angular' used like so, in this function definition? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741596772a2387459.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论