Thanks for raising this topic. I think it's very important.

On Fri, Jul 31, 2009 at 11:39, Simon Charette <> wrote:

> I don't want to sound rude but what's the point of a jquery'ish prototype?
> Isn't it like taking all the javascript sugar out of it?

I think we can all understand why jQuery's syntax is appealing to so many
people. It's a minimum number of keystrokes and abstracts away a lot of
programming concepts like loops. It's a no-brainer to understand that the
learning curve for non-programmers picking jQuery is considerably smoother.

Take, for instance, this code:

    var elements = document.getElementsByName('p')
    for (var i = 0; i < elements.length; i++) {
      elements[i] ...

If you explain to a designer that he has to write stuff like this to apply
some basic behavior to a web page—like hiding all the paragraphs—he will say
"WHAT?!" Then people discover jQuery, and say "that's more like it!"


Now, I hate `for` loops too (I only use them for code that *must* be
of maximum speed efficiency, which is rare) and
one of my favorite features in Prototype is Enumerable. I think jQuery took
its syntax too far by abstracting loops away from
users. For blogs, simplicity is awesome, but for creating real applications
it's bad.

For example, a thing that happened to GitHub in their early day is this:

    $('#content div.some_class')
      .click(function(){ ... })
      .mouseover(function(){ ... })

Quite innocent looking code, right? It's easy to forget that you're looping.
Well, this jQuery code delayed displaying of some pages by several seconds,
often showing the dreaded "the script on this site is taking too long" alert
message from the browser. What happened is that this behavior operated on
elements on a commit diff page, and for extremely large commits there was a
*huge* amount of 'div.some_class' elements—and whatever the amount was, this
single line of code looped *twice* over all of them.

They solved this with event delegation, by listening events on the
'#content' element as they should.

Now, with Prototype you have to write loops:

    $$('#content div.some_class').each(...)

and this is good because it makes you *know* what you're doing, and
enables you to apply several operations
in  a single iteration, avoiding the need to loop again like the jQuery

If you really want to avoid writing `each` for dead-simple iterators,
Prototype offers `invoke`:

   $$('#content div.some_class').invoke('removeClassName', 'some_class')

This still makes you aware that you're dealing with collections.

Now, Prototype 2 will not extend Element prototype anymore, so $$ will
return an array of wrapper-elements that have `addClassName()`, `hide()` and
others available on
them. This opens a possibility that this array could also
be augmented in some way, but I don't think it should offer jQuery-like
syntax for the reasons stated
above. I don't remember hearing the core team discuss this collection
object, so maybe now is the time.

Any suggestions how we can deal with collections in a simple way, but still
have slight differences in syntax compared to dealing with a single element?

Mike: Thanks for the suggestion and example implementation,
but NodeList is a very bad name since it already exists in the DOM and has
quite different semantics ;)

You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to