Reputation: 1664
In an attempt to learn JS OOP I am viewing the source code of jQuery to better understand how they do things. My question may seem simple, but I'm having trouble understanding the reasoning behind several variables that jQuery has defined at the top of their library. The code is shown below.
(function( window, undefined ) {
// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
navigator = window.navigator,
location = window.location;
....rest of code
What I don't understand is why they created variables for the document, navigator, and location objects. Does this resolve some type of browser bug? I don't understand the benefit of doing this.
Upvotes: 0
Views: 97
Reputation:
They're doing that so that, if some other script has mistakenly (or intentionally) created variables called document
, navigator
, or location
, they won't affect jQuery's use of those variables.
Upvotes: 3