Reputation: 14379
Modernizr starts with the following:
window.Modernizr = (function(window,document,undefined) { ...
...but why have window and document been passed as parameters? Is it something to do with differences between browsers? Or is it simply so the can't be redefined?
Upvotes: 1
Views: 75
Reputation: 318488
The parameters when calling that function are the following: (this, this.document)
So it's guaranteed that window
is the global object, document
is the document object and undefined
is undefined.
It also results in a small performance improvement; see Why does jQuery has a "window=this" at the very begining and say it would speed up references to window? for details
Upvotes: 2
Reputation: 174957
I believe it's for efficiently. window
and document
don't have to be fetched every time Modernizr needs it, but rather, a cached version of it.
Upvotes: 0