Thursday, May 10, 2007

A Judicious Use of Javascript

Ought to write more. Yesterday: "Maybe it is that I've been blessed with no memory." Today, however, I reconsider. There's a worthwhile lesson manifest in the CPU/RAM tradeoff. While blessed in some capacity, I still need to compensate. So. Ought to write more.

Last night was interesting, at least. Devoted to better Javascript understanding. Processed various forms of Douglas Crockford, JS guru at Yahoo!. He's wonderfully clever, gives great presentations with refreshingly good jokes. He promotes JS as a globally misunderstood language, and I'll admit I was guilty.

Javascript succeeded in what Java aimed to do. Its roots in the burgeoning browser industry were fraught with design errors, many of which persist. Doesn't really contain Unicode. That fucking global namespace. Its specifications result from a tug-of-war match fought in Europe by competing American companies. It's badly named, and abounds with bad ideas. Separate Math class, other bad Java residuum. But I'm still altogether taken.

He claimed it to be a functional language, and though unconvinced I'll still recognize closure as its lambda, and fundamentally important. Through linkage it manages inheritance. Labelled breaks, plus operators like && and || and === have interesting and useful functionality.

Genius, though? DYNAMIC OBJECTS. He got that point across. Objects are just containers. Big hash tables, really, and to any one you can add extra properties or methods. Want to give every Array your own method? Want to create an object? {}. There. It's lambda for anything static.

The global thing is a pain, but there seem to be sufficient ways around it. Crockford encapsulates his own YAHOO object, with its own namespace, separate from the global window. That's enough to manually establish scope.

Great Crockford quote, from another talk: "On the web, bugs don't get fixed." Every decision lingers. Most people update browsers when they update computers. It's a sad state of affairs, and you're left with multiple implementation differences between DOM APIs, but it's what's necessary for innovation.