当前位置:首页 >> 网络编程

javascript实现的HashMap类代码

复制代码 代码如下:
<script language = "javascript" >
function HashMap() {
    /**Map大小**/
    var size = 0;
    /**对象**/
    var entry = new Object();
    /**Map的存put方法**/
    this.put = function(key, value) {
        if (!this.containsKey(key)) {
            size++;
            entry[key] = value;
        }
    }
    /**Map取get方法**/
    this.get = function(key) {
        return this.containsKey(key) "A", "1");
hashMap.put("B", "2");
hashMap.put("A", "5");
hashMap.put("C", "3");
hashMap.put("A", "4");
alert(hashMap.size());

</script>