gpt4 book ai didi

javascript - 不要在循环中创建函数/不确定代码的含义

转载 作者:行者123 更新时间:2023-11-30 18:14:14 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to get around the jslint error ‘Don’t make functions within a loop.’

公平警告,我是一个初学者。我正在开发一个 google maps api v3 项目 ( http://jsbin.com/ofepet/9/edit ),我在 JSBin 上收到“不要在循环内创建函数”警告。我想修复它,但我使用的是从别处获得的代码,所以我很难准确理解发生了什么——尤其是最后 7 行。

简而言之,我对代码的理解不够好,无法将函数从循环中取出。错误出现在倒数第二行。

  function setMarkers(map, markers) {

for (var i = 0; i < markers.length; i++) {
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
html: sites[4],
icon: featureImage
});

var contentString = "Some content";

google.maps.event.addListener(marker, "click", function () {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
}

如何修复此错误?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com