/**
* Created by Administrator on 2016-10-15.
*/
/*
* Map
* */
(function () {
function jMap() {
var arr = [];
//增加
this.put = function (key,value) {
arr[key] = value;
};
//删除
this.remove = function (key) {
delete arr[key];
};
//遍历
this.each = function (fn) {
for (var key in arr){
fn(key,arr[key]);
}
};
//查询
this.get = function (key) {
try {
if (arr[key]){
return arr[key];
}else {
return null;
}
}catch (e){
throw new Error(e);
}
}
}
//使用
var country = new jMap();
country.put('01','中国');
country.put('02','美国');
country.put('03','英国');
country.put('04','韩国');
console.log(country.get('03'));
country.remove('02');
country.each(function (key,value) {
console.log(key +"---"+value);
});
})();
jMap的练习
最新推荐文章于 2021-09-01 11:53:49 发布