【发布时间】:2019-07-09 15:28:47
【问题描述】:
我正在浏览一些使用 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);
}
所以我了解 IIFE 以及它如何防止全局范围污染,但我不明白在上面的代码中将全局对象 google 和 window 传递给 IIFE 是什么。 有人能解释一下使用这种模式有什么好处吗?我们究竟在 IIFE 中使用 google 和 window 对象做什么?
【问题讨论】:
-
其实挺没意思的。
标签: javascript