[英]Parameters in bracket after a javascript function
I found a solution for google maps marker on stack-overflow. 我在堆栈溢出时找到了谷歌地图标记的解决方案。 Here is the link. 链接在这里。 Google Maps API Multiple Markers with Infowindows 带有Infowindows的Google Maps API多个标记
google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
return function() {
infowindow.setContent(content);
infowindow.open(map,marker);
};
})(marker,content,infowindow));
My question is: What is the purpose of (marker,content,infowindow) being placed behind the javascript function? 我的问题是:(标记,内容,信息窗口)放在javascript函数后面的目的是什么? And what is it called? 它叫什么? Thank you very much in advanced. 非常感谢您的进步。
这是一个自调用函数 - 这意味着在声明之后立即使用这些参数调用它
Please see the answer by Damian for the official name. 请查看Damian的正式名称答案。
However, this is simply executing the function created by executing the first function. 但是,这只是执行通过执行第一个函数创建的函数。
If we breakup the code into multiple lines, it may make more sense: 如果我们将代码分解成多行,可能会更有意义:
const makeAFuction = function(marker,content,infowindow){
return function() {
infowindow.setContent(content);
infowindow.open(map,marker);
};
}
const listener = makeAFunction(marker,content,infowindow);
google.maps.event.addListener(marker,'click', listener);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.