我在一个 Leaflet 项目中找到了一种我可以使用的函数。该函数是用 ES6 编写的,在 Firefox 和 Chrome 中都很好用。但是,我需要同时针对 IE 进行操作。在我的研究中,我发现目前 IE 不支持 ES6 箭头函数。此外,我还发现如果将 ES6 函数转换为 ES5,则该函数将在 IE 中起作用。但是,我已经试图将以下函数转换为 ES5 多天了,但都没有成功。我在这里找到了一些解决方案。请问有人能够查看我的脚本并告诉我我做错了什么吗?此外,ES6 的好处是什么呢?代码更短吗?谢谢。
以下是工作正常的 ES6 脚本:
points.map((p, i) => L.marker(p).bindPopup(`marker${'<strong>' + pointData[i].cityName + '</strong>' + ', ' + '</br>' + pointData[i].discrip + "<br /><a class='fancybox-thumb' ' style='width:150px;' rel='fancybox-button' rel='fancybox-thumb' data-fancybox-group='"+ pointData[i].popup +"' title='" + pointData[i].discrip + " ' href='graphic/"+ pointData[i].popup + "' ><img src='graphic/" + pointData[i].popup + "' alt='Image' ' style='width:150px;' ></a>" + "<br/><a href='http://www.google.com' target='_blank'>Cedellion Report</a>"}`))
.forEach(function(marker) {
map.addLayer(marker);
oms.addMarker(marker);
});
这是我最好的尝试,但没有成功。
points.map(function(p, i) {
L.marker(p).bindPopup(`marker${'<strong>' + pointData[i].cityName + '</strong>' + ', ' + '</br>' + pointData[i].discrip + "<br /><a class='fancybox-thumb' ' style='width:150px;' rel='fancybox-button' rel='fancybox-thumb' data-fancybox-group='"+ pointData[i].popup +"' title='" + pointData[i].discrip + " ' href='graphic/"+ pointData[i].popup + "' ><img src='graphic/" + pointData[i].popup + "' alt='Image' ' style='width:150px;' ></a>" + "<br/><a href='http://www.google.com' target='_blank'>Cedellion Report</a>"}`)})
.forEach(function(marker) {
map.addLayer(marker);
oms.addMarker(marker);
});