Hacker News new | past | comments | ask | show | jobs | submit login

You can make this yourself with Proxy. I get a lot of mileage out of this:

    // proxy to simplify loading and caching of getElementById calls
    const $id = new Proxy({}, {
        // get element from cache, or from DOM
        get: (tgt, k, r) => (tgt[k] || ((r = document.getElementById(k)) && (tgt[k] = r))),
        
        // prevent overwriting
        set: () => $throw(`Attempt to overwrite id cache key!`)
    });

Now if you have

    <div id="something></div>
You can just do

    $id.something.innerHTML = 'inside!';



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: