Pete Forde wrote:
http://dev.rubyonrails.org/ticket/5122
#5122 addressed adding document.getElementsByAttribute, alongside the
existing document.getElementsByClassName. We've found that while it's

I'm not arguing with the usefulness of this function but I am wondering why this should be used over selectors. I.E. You have:

document.getElementsByAttribute('subtotal').each(function(obj) {
    obj.onchange = handle_calc;
});

why not just do:

$$('[subtotal]').each(function(obj) {
    obj.onchange = handle_calc;
});

My concern is that what if later we want a function that will find all elements where attribute "changed" is equal to "true". Then we want to find all elements where the tag is "td" and the attribute "changed" is equal to "true". As you can see we can go on forever like this. As we keep adding methods to make element selection we end up with a bigger and bigger API that programmers have to learn to get the elements they need. Also prototype becomes large which is not good for a library that must be downloaded to every client.

OR

We can just use selectors. CSS selectors are very good as specifying elements in a document. Take a look at http://www.blooberry.com/indexdot/css/syntax/selectors/selectors.htm to see how capable they are. I don't know if prototype support all the syntax that CSS selectors are capable of yet but it seems to me that is where the effort should be placed and not on adding to the API. Selectors are concise and people already know them from CSS (so nothing new to learn).

The only advantage to special purpose selector functions is perhaps performance but I have found the selectors code quite efficient. Especially if you keep a few things in mind. See my post from the 31st for tips on how to keep performance good when using selectors.

Just my two cents. I welcome disagreements. :)

Eric

_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to