Keeping up with the Javascript learning effort. I am looking at the following code which aims to add functions to an object keeping them unique, something like adding callback functions to an event kind of thing.
var store = {
nextId: 1,
cache: {},
add: function(fn) {
if(!fn.id){
fn.id = store.nextId++;
return !!(store.cache[fn.id] = fn);
}
}
};
The code works well but now I would like to execute those functions and I haven't been able to figure that part out.
So far I have tried to call the two functions directly as methods of the store.cache object which gives me the error "Object# has no method 'blah'". Also I tried doing a loop as if store.cache was an array of functions but that didn't work either.
Thanks for any help.
store.cache[1](),store.cache[2](), etc.