const cache = new Map();
function createHandler(id) {
const data = { id, value: new Array(1000).fill(id) };
cache.set(id, data);
return function(action) {
if (action === 'get') return data;
if (action === 'clear') cache.delete(id);
};
}
const handler1 = createHandler('user-1');
const handler2 = createHandler('user-2');
handler1('clear');
console.log(cache.size);
console.log(handler1('get').id);
Ответ: 1, user-1
JavaScript test | #JavaScript & Max