News for hackers. Stuff that matters.
Re:Nine Javascript Gotchas by aston on Thursday February 14, 2008 @05:00PM (#116109)
Actually, I'd argue that relying on magical global variables mapping to page elements is bad practice in the first place.

If you want an element by ID, that's what document.getElementByID is for (or $ if you're using a JS framework). If you want a form element by its name (why not it's id?), you should go out to get that specifically.

Re:Nine Javascript Gotchas by gruseom on Thursday February 14, 2008 @05:27PM (#116125)
My JS is compiled from higher-level source; at the source level there is no duplication and it's simpler to use a variable. Moroever, using getElementById is 60% slower than a global variable in FF and more than 10x slower in IE. For the app I'm building, this matters a lot.
Re:Nine Javascript Gotchas by aston on Thursday February 14, 2008 @06:54PM (#116165)
Of course it's faster to use a precomputed reference than to find an element in the DOM. I can't see the "overhead" of manually storing a reference to a DOM element in a variable ever mattering in any application. Grab it once and you're done.
Re:Nine Javascript Gotchas by eusman on Thursday February 14, 2008 @07:57PM (#116195)
the only sure thing is that the whole javascript perfomance/memory footprint/cross-browser/degrade challenge can drive someone crazy!