r/javascript • u/gst • Mar 18 '09
Signs That Your JavaScript Skills Need Updating
http://odetocode.com/Blogs/scott/archive/2009/03/17/12659.aspx2
u/mollymoo Mar 18 '09
I wondered why so many JavaScript sites were so damned slow. Now I know: idiots using a bloated library to replicate the functionality you can get with built-in DOM features. If I just want to get an element by ID I'm going to use document.getElementById. That's what it's there for and it's what the library will be using after a couple of layers of indirection and bloat.
Not that there isn't a place for jQuery and the like, but using them for stuff the DOM can already do is just silly.
1
-1
u/bob11235 Mar 18 '09 edited Mar 18 '09
Sometimes I like to mix javascript and markup. If there's a bit of code that's only used on a particular page, then why not stick it in that page. I also do something like this for event handlers:
<input id="name_field" onclick="UserPageController.nameWasClicked()" />To me, this makes it really easy to track down the code for the event.
6
u/itsnotlupus beep boop Mar 18 '09
weak article, but let me nitpick anyway:
Yes, use external JS files for static and highly-cacheable code. But if you generate script data dynamically on your server, don't make the browser do an extra request to get to it. Inline the darn thing.
Sure, libraries are nice. If all you're doing is a little bit of ajax, and hooking a few event handlers, and the download size is important (it happens), you can write your own tiny library.
I still like alert(), damnit. All you console.error() weenies can go to hell.
Anyway, if you're going to impress people with your JS up-to-dateness, at least make a stand on something a tiny bit controversial.
How about "People adding prototype methods to builtin objects should be shot"?
Or maybe "Why is it valid to have labels: before any statement if you can only use the ones placed before a loop construct? Add goto to the EcmaScript spec now!"
If you're going to troll, at least do it right.