javscript中自定义键值对(Dictionary)

来源:互联网 发布:linux core文件 编辑:程序博客网 时间:2024/05/06 14:55
//自定义键值对对象function Dictionary() {    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;    };}<pre name="code" class="javascript">//然后就可以通过var typeArr = new Dictionary();typeArr.put(1, "1"); //存typeArr.get(1);//=1 取typeArr.remove(1);//删除指定元素typeArr.isEmpty();//删除所有元素typeArr.size();//获取长度

                                             
0 0
原创粉丝点击