r/javascript • • Mar 18 '09

Signs That Your JavaScript Skills Need Updating

http://odetocode.com/Blogs/scott/archive/2009/03/17/12659.aspx
2 Upvotes

6 comments sorted by

6

u/itsnotlupus beep boop Mar 18 '09

weak article, but let me nitpick anyway:

  1. 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.

  2. 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.

  3. 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.

2

u/SimonS Mar 18 '09
alert = console.error;

I've actually been involved projects where all debug code has been disabled with

alert = function(){}

at the top of released files. Initially started as a make-doubly-sure measurement, but then leaving alerts in became the standard out of laziness.

1

u/itsnotlupus beep boop Mar 18 '09

ouch. that's about as healthy as window.onerror=function(){return true};

For all my willingness to defy politically-correct coding rules, my alert() statements never stay in one file for more than 15 minutes.

2

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

u/gzur Mar 18 '09

anti-article about anti-patterns

-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.