if (typeof weakref === 'undefined' || typeof finalizationregistry === 'undefined') {  console.error('weakref or finalizationregistry is not supported in this environment.'); } else {  function makeweakcached(f) {  const cache = new map();  const registry = new finalizationregistry(key => {  cache.delete(key);  console.log(`cache entry for "${key}" has been garbage collected and removed.`);  });  return key => {  const ref = cache.get(key);  if (ref) {  const cachedobj = ref.deref();  if (cachedobj !== undefined) {  console.log(`retrieving cached message for: "${key}"`);  return cachedobj.message;   } else {  console.log(`cached message for "${key}" has been garbage collected.`);  cache.delete(key);  }  }  const fresh = { message: f(key) };  cache.set(key, new weakref(fresh));  registry.register(fresh, key);  console.log(`generated and cached message for: "${key}"`);  return fresh.message;  };  }  function gethelloworld(name) {  return `hello world, ${name}!`;  }  const gethelloworldcached = makeweakcached(gethelloworld);  function demohelloworldcaching() {  console.log(gethelloworldcached("al ice"));   console.log(gethelloworldcached("bo b"));   console.log(gethelloworldcached("al ice"));   console.log(gethelloworldcached("bo b"));   // remove strong references and suggest garbage collection  // remove strong references by not holding onto the messages  }  demohelloworldcaching(); }
Israel