JavaScript needs frameworks


var result = [];
var tab = document.getElementsByTagName("div");
for (var i=0; i<tab.length; i++)?
	if (/.*[\s^]myClass[\s$].*/
	  .match(tab[i].styleClass))
		var tmp = tab[i].childNodes;
for (var j=0; j<tmp.length; j++)?
	if (/.*[\s^]myOtherClass[\s$].*/
	  .match(tmp[i].styleClass))
		result.push(tmp[i]);
for (var i=0; i<result.length; i++)?
	result[i].addClassName("invisible");

				

This ugly code raw JavaScript code could have been written in a much easier to read, much easier to write, much easier to maintain, and much more cross borwser compatible way :

$$("div.myClass .myOtherClass")?
  .invoke("addClassName", "invisible");
				

This example is so simple, just because we have used Prototype . That's why Prototype is considered for us as part of the core javascript at our level, like java.lang is to Java.

We could have done the same with:

  • Listening to custom events
  • Managing object inheritance
  • Dealing with Ajax requests?

This is why we have to use Frameworks in JavaScript. Raw APIs are hard to read, hard to work with, and a little different in each navigator.

Prototype give us a good language and good APIs, Archetype will just improve a bit this, structure your code, and renders it globallty much more readable than without it. It will also take care of the strangest browser behaviors in order for you to keep working on your main code, not on ugly things.