I want to make a map object that key is object.
But, JavaScript only allows string as a hash key. (at least before ECMAScript6 comes?)
So, I tried to write auxiliary functions to emulate, hash-ish (but actually linear search). Are there any suggestions on improvement?
var tabInfo = {};
var tabInfoKey = 0;
function getTabInfoItem(tab) {
console.log("getTabInfoItem", tab);
for(var key in tabInfo) {
if(tabInfo[key].tab === tab) {
return tabInfo[key].info;
}
}
}
function setTabInfoItem(tab, info) {
console.log("setTabInfoItem", tab, info);
for(var key in tabInfo) {
if(tabInfo[key].tab === tab) {
tabInfo[key] = {
tab: tab,
info: info
};
return;
}
}
tabInfoKey++;
tabInfo[tabInfoKey] = {
tab: tab,
info: info
};
}
function deleteTabInfoItem(tab) {
console.log("deleteInfoItem", tab);
for(var key in tabInfo) {
if(tabInfo[key].tab === tab) {
delete tabInfo[key];
return;
}
}
}