>>3452The options are the decider for what you get. no Comparision, it's a hash table.
//setting the store
var index_store = {};
var store = [];
function hash(opts){
return "" + (opts.noimage ? 1 : 0) + (opts.notext ? 1 : 0) + (opts.somethingirrelev
an ? 1 : 0);
}
function storeValue(optshash, value){
index_store[optshash] = store.length;
store.push(value);
}
var opts_1 = hash({noimage:true, notext:false, somethingirrelevant:tr
ue});
var value_1 = "asdf";
storeValue(opts_1 , value_1);
var opts_2 = hash({noimage:true, notext:false, somethingirrelevant:fa
lse});
var value_2 = "asdf";
storeValue(opts_2 , value_2);
// later evaluation
var opts_1 = hash({noimage:true, notext:false, somethingirrelevant:tr
ue});
function getIfCached(opts){
if(index_store[opts])
return store[index_store[opts
]];
}
var opts_3 = hash({noimage:false, notext:false, somethingirrelevant:tr
ue});
console.log(getIfCache
d(opts_1));
//asdf
console.log(getIfCache
d(opts_2));
//asdf
console.log(getIfCache
d(opts_3));
//undefined