Skip to main content
deleted 78 characters in body
Source Link
Boris Burkov
  • 14.7k
  • 20
  • 84
  • 119

I'm importing Angular 1.4 in my entry point module of Webpack build as a CommonJS module (i.e. with var angular = require("angular");), but somehow it becomes available in global namespace of the browser (i.e. as window.angular, if I'm not mistaken).

In the source code of Angular 1.4 I found the following lines:

(function(window, document, undefined) {'use strict';

...

var
    msie,             // holds major version number for IE, or NaN if UA is not IE.
    jqLite,           // delay binding since jQuery could be loaded after us.
    jQuery,           // delay binding
    slice             = [].slice,
    splice            = [].splice,
    push              = [].push,
    toString          = Object.prototype.toString,
    getPrototypeOf    = Object.getPrototypeOf,
    ngMinErr          = minErr('ng'),

    /** @name angular */
    angular           = window.angular || (window.angular = {}),
    angularModule,
    uid               = 0;

So, do I get it right, that upon require, this line:

angular           = window.angular || (window.angular = {})

checks, if global angular object is available and if it is not, creates it. So, angular silently introduces side-effect? What's the purpose of () around window.angular = {}?

I'm importing Angular 1.4 in my entry point module of Webpack build as a CommonJS module (i.e. with var angular = require("angular");), but somehow it becomes available in global namespace of the browser (i.e. as window.angular, if I'm not mistaken).

In the source code of Angular 1.4 I found the following lines:

(function(window, document, undefined) {'use strict';

...

var
    msie,             // holds major version number for IE, or NaN if UA is not IE.
    jqLite,           // delay binding since jQuery could be loaded after us.
    jQuery,           // delay binding
    slice             = [].slice,
    splice            = [].splice,
    push              = [].push,
    toString          = Object.prototype.toString,
    getPrototypeOf    = Object.getPrototypeOf,
    ngMinErr          = minErr('ng'),

    /** @name angular */
    angular           = window.angular || (window.angular = {}),
    angularModule,
    uid               = 0;

So, do I get it right, that upon require, this line:

angular           = window.angular || (window.angular = {})

checks, if global angular object is available and if it is not, creates it. So, angular silently introduces side-effect? What's the purpose of () around window.angular = {}?

I'm importing Angular 1.4 in my entry point module of Webpack build as a CommonJS module (i.e. with var angular = require("angular");), but somehow it becomes available in global namespace of the browser (i.e. as window.angular).

In the source code of Angular 1.4 I found the following lines:

(function(window, document, undefined) {'use strict';

...

var
    msie,             // holds major version number for IE, or NaN if UA is not IE.
    jqLite,           // delay binding since jQuery could be loaded after us.
    jQuery,           // delay binding
    slice             = [].slice,
    splice            = [].splice,
    push              = [].push,
    toString          = Object.prototype.toString,
    getPrototypeOf    = Object.getPrototypeOf,
    ngMinErr          = minErr('ng'),

    /** @name angular */
    angular           = window.angular || (window.angular = {}),
    angularModule,
    uid               = 0;

So, do I get it right, that upon require, this line:

angular           = window.angular || (window.angular = {})

checks, if global angular object is available and if it is not, creates it. So, angular silently introduces side-effect?

edited title
Link
Boris Burkov
  • 14.7k
  • 20
  • 84
  • 119

Does Angular registerassign itself globally asto `window.angular` globally, when loaded as CommonJS module?

Source Link
Boris Burkov
  • 14.7k
  • 20
  • 84
  • 119

Does Angular register itself globally as `window.angular`, when loaded as CommonJS module?

I'm importing Angular 1.4 in my entry point module of Webpack build as a CommonJS module (i.e. with var angular = require("angular");), but somehow it becomes available in global namespace of the browser (i.e. as window.angular, if I'm not mistaken).

In the source code of Angular 1.4 I found the following lines:

(function(window, document, undefined) {'use strict';

...

var
    msie,             // holds major version number for IE, or NaN if UA is not IE.
    jqLite,           // delay binding since jQuery could be loaded after us.
    jQuery,           // delay binding
    slice             = [].slice,
    splice            = [].splice,
    push              = [].push,
    toString          = Object.prototype.toString,
    getPrototypeOf    = Object.getPrototypeOf,
    ngMinErr          = minErr('ng'),

    /** @name angular */
    angular           = window.angular || (window.angular = {}),
    angularModule,
    uid               = 0;

So, do I get it right, that upon require, this line:

angular           = window.angular || (window.angular = {})

checks, if global angular object is available and if it is not, creates it. So, angular silently introduces side-effect? What's the purpose of () around window.angular = {}?