0

I am going through some code which is making use of google maps API .

function initMap(){
(function(google , window){
var center = {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8
};
var map = new google.maps.Map(document.getElementById('map'), center);    
})(google , window);
}

So I understand IIFE and how it prevents global scope pollution but I do not understand what passing the global objects google and window to the IIFE , achieve in the above code . Could someone please explain what is the advantage of using this pattern and what exactly are we doing with the google and window object inside the IIFE?

Knownow
  • 353
  • 1
  • 4
  • 17

1 Answers1

1

what exactly are we doing with the google and window object inside the IIFE?

Nothing useful, and nothing respectively.

window isn't used at all inside the function.

google is used, but synchronously. If it was used asynchronously then it might be useful to pass it so its value didn't get overwritten between multiple uses of it, but that isn't the case here.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335