Why I like Prototype?

Lately I have read articles which were comparing, bashing and dissecting multiple Javascript libraries (or framework, but I wouldn’t go that far with their definition). And as each of those articles took a side for their favorite and disregarding the others. I as well would like to show my appreciation to my favorite Javascript library Prototype, and this without bashing the other ones.

So what do I like about Prototype?

  • The way you can create DOM elements, and filling them in with values in one single line:
    $('wrapper').insert(
    new Element('div', { class: 'a_class_name' }).update('Some text')
    );
  • Working with collection of elements:
    $$('.foo').invoke('observe', 'click', function(el) {
    // handle click event on any of the elements in the collection
    });
  • Executing a portion of code several times without using loops:
    (10).times(function(){
    // code to execute 10 times
    });
  • Variable type checking utilities:
    Object.isArray();
    Object.isNumber();
    Object.isString();
    Object.isUndefined();
    Object.isHash();
    Object.isFunction();
    Object.isElement()
  • Function scope binding:
    var a = {
    // define some property
    };
    function() {
    // access a object properties through this
    }.bind(a);
  • And many more, alongside with the new features in 1.7

Of course the before mentioned reasons or not enough to convince people to switch to Prototype from the libraries they use, but that wasn’t the intent either. Even if other libraries get new adepts on a daily basis (you know I refer to jQuery) I think the Prototype community is far from dying, it just doesn’t like getting into the spotlight.

And last but not least Prototype has a very good (from my perspective) API documentation, yes, the one in the old format.


Filed under Code, Discussion