当前位置 : 主页 > 网络编程 > JavaScript >

JS自定义Map对象

来源:互联网 收集:自由互联 发布时间:2021-06-28
JS自定义Map对象 /** * JS自定义Map对象 * @constructor */function ArrayMap(){ this.data = new Array(); this.put = function(key,value){ this.data[key] = value; }; this.get = function(key){ return this.data[key]; }; this.remove = func
JS自定义Map对象
/**
 * JS自定义Map对象
 * @constructor
 */
function ArrayMap(){
    this.data = new Array();

    this.put = function(key,value){
        this.data[key] = value;
    };

    this.get = function(key){
        return this.data[key];
    };

    this.remove = function(key){
        this.data[key] = null;
    };

    this.isEmpty = function(){
        return this.data.length == 0;
    };

    this.size = function(){
        return this.data.length;
    };
}

//使用示例
/**
 var map = new ArrayMap();
 map.put("CN", "China");
 map.put("EN", "English");
 map.get("CN");
 **/
网友评论