What do you do after you've surfed out all the help wanted ads? Work on ways to make yourself more employable. (Or something like that.)
I'm reworking my own personal JavaScript library, "FlangeLib". If you surf around on adamv.com with the
Web Developer extension for FireFox you can find flangelib.js, though there isn't any official distribution yet.
Flangelib is a set of JavaScript code that has agglomerated since I started hacking AJAX into The Conversatron. Since it was born of hacking, there's no design principles. And since I'm using it more and more in JavaScript projects, now would be a good time to clean it up.
One of the up-front design decisions to make is, "Extend prototypes or not?"
JavaScript is object-oriented, but it's prototype-based instead of class-based. (Though it's easy to create C++/Java/C#-style classes with prototypes.) You can add functions to an object's
prototype to give all objects created from that prototype new methods.
You can write
Array.prototype.do_something = function(){...} and then call it like:
anArray.do_something()instead of:
do_something(anArray)The downside? Adding to an object's prototype pollutes the
for..in construct. All of the built-in properties of objects are hidden from
for..in, but any you add are visible. This makes
for..in semi-worthless for iterating only the "data" properties of an object.
The other problem is that some of the object types in Internet Explorer aren't dervied from Object (or Array), so extending base prototypes won't affect objects returned from the DOM. This means that for some functions you're forced into making them stand-alone anyway. (And in most browsers, a function's
arguments list is of type
Arguments instead of
Array, which is a pointless misfeature.)
Thus, I've talked myself into not extending objects via
prototype.
I may add properties to constructor functions, to create the equivalent of static class methods, though.