4

Possible Duplicate:
JavaScript function aliasing doesn't seem to work
Set document.getElementById to variable

Code would be more efficient if this was possible:

var min = document.getElementById;

and then call document.getElementById() using min().

Not trying to write minified code but in this particular case one can reduce scope lookup and shorten some lines.

Is this a syntax issue or a limiation on the language?

Community
  • 1
  • 1

1 Answers1

6

When you call foo.bar() then this is set to foo inside bar When you copy foo.bar to window.bar then call window.bar(), this is set to window.

getElementById has to operate on a DOM document object.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • `window` is the default object, it is the same question just making `window` explicit instead of looking up the scope chain. – Quentin May 23 '12 at 18:12