javascript "google.maps.event.addDomListener(window, 'load', initialize); 是什么" 意思是?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30960231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what does "google.maps.event.addDomListener(window, 'load', initialize);" mean?
提问by Feath
What does this mean?
这是什么意思?
google.maps.event.addDomListener(window, 'load', initialize);
I have the function 'initialize()' but I also added two paramters, longitude and latitude so it's like this:
我有函数 'initialize()' 但我还添加了两个参数,经度和纬度,所以它是这样的:
function initialize(longitude, latitude){
}
because of this do I have to do anything to the 'initialize' in the line:
因此,我必须对行中的“初始化”做任何事情:
google.maps.event.addDomListener(window, 'load', initialize);
采纳答案by geocodezip
The google.maps.event.addDomListeneradds a DOM event listener, in this case to the window
object, for the 'load' event, and specifies a function to run.
所述google.maps.event.addDomListener增加了DOM事件侦听器,在这种情况下到window
对象,为“负载”事件,并指定要运行的功能。
from the documentation:
从文档:
addDomListener(instance:Object, eventName:string, handler:function(?), capture?:boolean)
Return Value:MapsEventListener
Cross browser event handler registration. This listener is removed by calling removeListener(handle) for the handle that is returned by this function.
addDomListener(instance:Object, eventName:string, handler:function(?), capture?:boolean)
返回值:MapsEventListener
跨浏览器事件处理程序注册。通过为此函数返回的句柄调用 removeListener(handle) 来删除此侦听器。
The initialize
in google.maps.event.addDomListener(window, 'load', initialize);
is a function pointer, you can't pass arguments with that. To pass in arguments, wrap it in an anonymous function (that doesn't take arguments):
该initialize
中google.maps.event.addDomListener(window, 'load', initialize);
是一个函数指针,你不能传递与参数。要传入参数,请将其包装在一个匿名函数中(不带参数):
google.maps.event.addDomListener(window, 'load', function () {
initialize(latitude, longitude);
});
回答by GolezTrol
It looks like it calls initialize
when the DOM is loaded, but probably without the parameters, if I interpret the docscorrectly.
它看起来像是initialize
在加载 DOM 时调用,但如果我正确解释文档,则可能没有参数。
But you could wrap the call inside another function and pass that to the method. It can be an anonymous function, like so:
但是您可以将调用包装在另一个函数中并将其传递给该方法。它可以是一个匿名函数,如下所示:
google.maps.event.addDomListener(window, 'load', function(){
initialize(50.0000, 60.0000);
});