var BASE = BASE||{};
BASE.Map = function () {
var _hash = {};
this._hash = _hash;
this.put = function (key,value) {
_hash[key] = value;
};
this.get = function (key) {
if(_hash[key] || _hash[key] === 0 || _hash[key]===false){ //防止 value为 0或者false 的情况 js类型自动转换
return _hash[key];
}else {
return null;
}
} ;
this.remove = function (key) {
if(_hash[key] || _hash[key] === 0 || _hash[key]===false){
delete _hash[key];
}
};
this.size = function () {
var count = 0;
for(var k in _hash){
count++;
}
return count;
};
this.toArray = function () {
var re = [];
for(var k in _hash){
re.push(_hash[k]);
}
return re;
} ;
this.each = function (handler) {
for(var e in _hash){
handler&&handler(_hash[e]);
}
}
};
再学JavaScript-第二课-模拟Map
最新推荐文章于 2018-10-17 10:35:11 发布