Skip to content

Instantly share code, notes, and snippets.

@adrianmgg
Created March 19, 2026 21:19
Show Gist options
  • Select an option

  • Save adrianmgg/da4ee908d7bcb573ffc50c10eb27c3b3 to your computer and use it in GitHub Desktop.

Select an option

Save adrianmgg/da4ee908d7bcb573ffc50c10eb27c3b3 to your computer and use it in GitHub Desktop.
WIP collection of general-purpose JS helper things i've written
// a WIP collection of general-purpose JS helper things i've written
// figured it made sense to start collecting these things in one place
// rather than them being lost to time forever in old scripts
const util = (() => {
const idProxy = new Proxy({}, {
get(target, prop, receiver) { return document.getElementById(prop); },
});
return { idProxy };
})();

idProxy

const { foo, bar } = util.idProxy;
// is equivalent to
const foo = document.getElementById('foo');
const bar = document.getElementById('bar');
const { 'hello-world': hello_world } = util.idProxy;
// is equivalent to
const hello_world = document.getElementById('hello-world');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment