5

I'm perusing the AngularJS source code and couldn't help but notice the following:

_angular          = window.angular,
/** @name angular */
angular           = window.angular || (window.angular = {}),

This line makes sense to me:

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

"Use angular if already defined (from a previous inclusion?) in window, or assign window.angular to an empty object and set angular local variable to window.angular."

Some questions:

  1. Why would window.angular already be defined (other than the obvious case of someone has already included it), and why would we care?
  2. Why assign _angular as well as angular?

1 Answer 1

3

Going through the commit history on GitHub, this is for noConflict mode, the case where you have an old reference to a variable called angular you want to preserve.

Here is the commit that added _angular in.

The feature was then removed in this commit and the _angular reference is redundant at this point.

I'll raise an issue on GH or make a pull request shortly. Update - made a PR.

Sign up to request clarification or add additional context in comments.

2 Comments

You're fast, haha = )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.