It might be something easy that I'm overlooking, but I don't see what  
I'm looking for as part of either Enumerable or Array.

I've found myself needing to set attributes on arrays of Elements.  I  
know this is trivial with each(), but I'm looking for a cleaner way  
to do it.  The idea is similar to Enumerable.pluck(), but as a setter  
instead of a getter. Perhaps there is already an easy way to do it  
that I'm missing.  I'd call it Enumerable.apply() or .setEach()/ 
extendEach().


apply: function(iterator, attribute, value) {
    return this.map(function(item, index) {
       item[attribute] = value;
    });
},

Use case:
$$('#myFormId input').apply('disabled', true);
$$('#myFormId input').apply('checked', '');

It could be made a bit more robust with something like this:

apply: function(iterator, hash) {
    return this.map(function(item, index) {
       Object.extend(item, hash);
    });
},

Even better, the function could be reworked to auto-detect the number  
of parameters passed (or whether the first is a string or an object),  
and act accordingly.

Useful? Not useful?  I'm an idiot and overlooked something simple?

Your feedback is encouraged.



TAG

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to