首頁  >  文章  >  web前端  >  js中產生map物件的方法_javascript技巧

js中產生map物件的方法_javascript技巧

WBOY
WBOY原創
2016-05-16 17:04:351401瀏覽
複製程式碼如下程式碼:

var Map = function(){
this._fentrys = new.家族();

this.put = function(key, value){
if (key == null || key == undefined) {
return;
}
var index = this._getIndex(key);
if (index == -1) {
var entry = new Object();
entry.key = key;
entry.value = 值;
this._entrys[this._entrys.length] = 入境;
}else{
this._entrys[index].value = value;
}
};
this.get = function(key){
var index = this._getIndex(key);
返回(索引!= -1)?
};
this.remove = function(key){
var index = this._getIndex(key);
if (index != -1) {
this._entrys.splice(index, 1);
}
};
this.clear = function(){
this._entrys.length = 0;;
};
this.contains = function(key){
var index = this._getIndex(key);
返回(索引!= -1)?
};
this.getEntrys = function(){
return this._entrys;
};
this._getIndex = function(key){
if (key == null || key == undefined) {
return -1;
}
var _length = this._entrys.length;
for (var i = 0; i var entry = this._entrys[i];
if (入境== null || 入境==未定義) {
繼續;
}
if (entry.key === key) {//相等
return i;
}
}
回傳-1;
};
this._toString = function(){
var string = "";
for (var i = 0; i string = this.getEntrys()[i].key "::" this.getEntrys()[i ] 。
if(i!=this.getEntrys().length-1){
string = ";";
}
}
回傳字串;
};
};

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn