 <p>When you assign a function to a different variable, it's <code>this</code> value changes. Since <code>getElementById</code> expects <code>this</code> to be an element, you're getting an error.</p> <p>If you're in an environment where you can use <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind" rel="nofollow"><code>bind</code></a>, use it:</p> <pre><code>(function(){ var t = document.getElementById.bind(document); t('element-id'); })(); </code></pre> <p>This'll ensure that <code>t</code>'s <code>this</code> will stay the <code>document</code> object.</p> <hr> <p>If you can't use <code>bind</code>, you'll have to create an intermediary function:</p> <pre><code>(function() { function t (id) { document.getElementById(id); } t('element-id'); })(); </code></pre>