Map() is not defined in Google Chrome

六眼飞鱼酱① 提交于 2019-12-01 06:44:15

Some ES harmony features, including Map(), did already exist in Chrome at the end of 2011. It's just disabled by default.

To enable the feature, visit chrome://flags/, and enable "Enable experimental JavaScript". Then restart the browser and enjoy the new features.

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

Map is now in Chrome version 38 (beta as of 29-Aug-2014), which means it will get to stable very shortly. If you have 38, no need to enable experimental features.

Why not use a simple array?

var NameMap;
var DistanceMap;

function FillMaps(){
    NameMap = new Array();
    DistanceMap = new Array();

    NameMap[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[parseInt(location)];
    if(result == undefined){
        result = "Unknown";
    }
    document.getElementById('loc').innerHTML = result;
}

"Danger! Experimental technology!"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Its possible the code here can implement Map for Chrome, but I've not tried:

http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!