In some Javascript code which uses immediate function, it has argument window or document like the following:
(function (window, document) {
  ...
})(window, document);
However, window and document are global objects and can be directly accessed as follow:
(function () {
  var userAgent = window.navigator.userAgent;
  ...
  var el = document.getElementById(...)
  ...
})();
What are the differences between the above two codes. Which is better way and why?
 
     
     
    