Google Chrome中没有定义Map() [英] Map() is not defined in Google Chrome
问题描述
我一直在寻找答案,但我只收到有关Google maps API的结果。我试图在JavaScript中使用地图将整数映射到字符串。一切都在Firefox中正常工作,但在Chrome中我在控制台中收到一条错误消息:
I've been searching for an answer but I'm only getting results regarding the Google maps API. I'm trying to use a map in JavaScript to map an integer to a string. Everything is working fine in Firefox but in chrome I get an error message in the console:
未捕获ReferenceError:映射未定义
Uncaught ReferenceError: Map is not defined
以下是一段参考代码:
var NameMap;
var DistanceMap;
function FillMaps(){
NameMap = new Map();
DistanceMap = new Map();
NameMap.set(01, "Araba/Álava");
}
function CheckName(_field){
var value = document.getElementsByName(_field.name).item(0).value;
var location = value.charAt(0) + value.charAt(1);
var result = NameMap.get(parseInt(location));
if(result == undefined){
result = "Unknown";
}
document.getElementById('loc').innerHTML = result;
}
推荐答案
一些ES和谐功能,包括 Map()
,在2011年底已经存在于Chrome中。默认情况下,它已被禁用。
Some ES harmony features, including Map()
, did already exist in Chrome at the end of 2011. It's just disabled by default.
启用该功能,请访问 chrome:// flags /
,并启用启用实验性JavaScript。然后重新启动浏览器并享受新功能。
To enable the feature, visit chrome://flags/
, and enable "Enable experimental JavaScript". Then restart the browser and enjoy the new features.
另一种方法是在命令行上传递 - js-flags = - harmony
标志。例如:
An alternative method is to pass the --js-flags=--harmony
flag on the command line. For instance:
chromium --js-flags=--harmony
chrome.exe --jsflags=--harmony
这篇关于Google Chrome中没有定义Map()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!