JavaScript is purported to have first-class functions, so this seems like the following ought to work:
var f = document.getElementById;
var x = f('x');
But it fails on all browsers, with a different cryptic error message on each one. Safari says “Type error”. Chrome says “Illegal invocation”. Firefox says “Could not convert JavaScript argument”.
Why?
Because in JavaScript functions arent bound to context (
this). You may usebind():