Why does jQuery tie their ajax request object to a window?

Why does JQuery ( latest source ) tie there Ajax Request Object to a window like this?

    return new window.XMLHttpRequest();

I'm asking b.c. in my source I don't do this.

I just do

return new XMLHttpRequest();

Answers


Because the XMLHttpRequest object is a child of the window object.

You can reference it as a lone object since window is the parent scope in the browser; i.e. the global scope. If the reference isn't in the local scope (closure), JavaScript keeps going up the scope chain until the reference found. Using window.XMLHttpObject prevents all the look ups by telling the browser exactly where to find it.


Need Your Help

Using angular to display different timestamps depending on age of object

javascript angularjs angularjs-filter

This is similar to the messages app on an iphone, where newer text messages you get will simply show you the time in a format like 9:55 PM, but once they are a day old it says Yesterday, and anything

jQuery Mb slider

jquery slider

I'm new to jQuery mb slider. I downloaded the zip file had a trial run, everything is working fine. But I need to disable the sliding functionality in jQuery mb slider. How to do that?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.