I'm code reviewing the following:
(function () {
'use strict';
window.angular
.module('moduleName')
.directive('DirectiveName', function () {
return {
restrict: 'AE',
templateUrl: '/app/moduleName/list/template.html',
controller: 'someController',
controllerAs: 'someCtrl',
}
});
}());
I've been using
angular
.module('myModule')
//etc
rather than starting with window.angular.
Since I presume angular is scoped against the window, is there any real, practical difference between these two syntaxes?
not at all. in browsers window is the global object,
and as written here - https://developer.mozilla.org/en-US/docs/Web/API/Window/window :
In web pages, the window object is also a global object. This means that:
global variables of your script are in fact properties of window:
var global = {data: 0}; alert(global === window.global); // displays "true"you can access built-in properties of the window object without having to type window. prefix:
setTimeout("alert('Hi!')", 50); // equivalent to using window.setTimeout. alert(window === window.window); // displays "true"
Any variable defined globally is attached to the window. So no there is no real practical difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With