Hi,

Thanks for your reply! I've already done so, but I'm not really a fan of
mixing something into external classes. I think of either wrapping it, or
just writing a simple one of my own instead.

Cheers,
Mikhail.


On Sun, Jan 24, 2010 at 7:30 AM, T.J. Crowder <t...@crowdersoftware.com>wrote:

> Hi,
>
> I doubt it'll make core, but there's no reason you can't do that for
> your own stuff:
>
> * * * *
> Hash.addMethods({
>    eachPair: function(iterator, context) {
>
>        return this.each(function(pair, index) {
>            iterator.call(context, pair.key, pair.value, index);
>        });
>    }
> });
> * * * *
>
> Or if you like to use named functions for the main bits (I do):
>
> * * * *
> Hash.addMethods((function(){
>
>    function eachPair(iterator, context) {
>
>        return this.each(function(pair, index) {
>            iterator.call(context, pair.key, pair.value, index);
>        });
>    }
>
>    return {eachPair: eachPair};
>
> })());
> * * * *
>
> FWIW,
> --
> T.J. Crowder
> Independent Software Consultant
> tj / crowder software / com
> www.crowdersoftware.com
>
> On Jan 23, 11:48 pm, Mikhail Kozhevnikov <ambl...@gmail.com> wrote:
> > Hello,
> >
> > Why not to have an iterator over the hash like
> > Hash.each_pair(function(key, value){...});
> > as a shortcut for
> > Hash.each(function(pair){
> >    var id = pair.key, obj = pair.value;});
> >
> > The point is that if one makes heavy use of hashes in code, this small
> > redundancies get really annoying. Why bother with reassignment at all?
> > Well, most importantly it makes make the code more readable, as the
> > name of the variable reflects the semantics, while "pair.value"
> > doesn't.
> >
> > Cheers,
> > Mikhail.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prototype & script.aculo.us" group.
> To post to this group, send email to
> prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to