Simon,
Indeed, I realized that what you suggested didn't imply an each()
function call thereafter, only after I clicked the 'Send' button.
(Didn't read the 'match' function in your code.) My apologies. Thus,
your suggestion is almost as equal as T.J. Crowder's one. (...moving
on)

A note to clarify; I do not believe that findAll().each() is the
'Prototype' way. Or, at least, I don't believe that they were designed
specifically to work that way. For small size arrays, this may be
irrelevant, but what I intended to say is that suggesting to
concatenate two iterative functions to achieve a goal is poor coding
habbit, regardless of the size of the object being iterated. The
comment wasn't directed to you specifically, but to those who quickly
suggest such things (and I see too often poor suggestions being given
in many forums).

That being said, I'm sorry if I offended you, or anyone in that
matter.

yanick


On Sep 16, 12:08 pm, "Simon Charette" <[EMAIL PROTECTED]> wrote:
> Sorry Yannick,
> but even if I agree with you that findAll().each() is the 'Prototype' way
> which i would prefer to the grep method i suggested.
> It still creates two iterations while the grep solutions doesn't.
>
> Thats the main reason why i suggested this formula.
>
> 2008/9/16 Yanick <[EMAIL PROTECTED]>
>
>
>
> > I have seen two responses using filter().each() (or grep().each()) and
> > I just wanted to say that, IMHO, this is not good practice, and thus
> > should not be recommanded as this creates two iterations over the same
> > array for the same purpose and encourages bad coding habbits. The
> > question is not "would this work?" but rather "is this the best way?"
> > The OP must've felt the same way, otherwise he would've used such
> > "double sequential loops way" in the first place. In fact, what T.J.
> > Crowder suggested is the most Prototype way. I hope we'll all learn
> > from this :)
>
> > yanick
>
> > On Sep 15, 12:24 pm, Grant Hutchins <[EMAIL PROTECTED]> wrote:
> > > It seems to me that Enumerable#findAll (aliased as select) is what you
> > > want for your first example.
>
> > > myArray.findAll( function(obj){ obj.className ==
> > > 'MyProtoClass' } ).each( function(obj){ obj.doStuff } );
>
> > > This way you're using the official Prototype way to do these
> > > operations.
>
> > > Grant
>
> > > On Sep 11, 6:17 pm, EMoreth <[EMAIL PROTECTED]> wrote:
>
> > > > Working with prototype from a long time ago I always need a function
> > > > that could do something just like the Strongly Type languages, as Java
> > > > or many others, that is a for ( ObjectClass object in
> > > > arrayLikeStructure ) to get all objects from that array that are from
> > > > the class ObjectClass and do something...
>
> > > > Since Javascript does not have this kind of Typed Class its is very
> > > > hard and annoying to do such thing... I recently tought two ways that
> > > > could make it work...
>
> > > > First (and simpler) is a foreach function that applyes on Enumerable
> > > > items and Accepts two functions.. the first one is a boolean that will
> > > > tell the code when the object is the class/type that I want, and the
> > > > second function should be the action at real... to apply in that
> > > > object. Something like :
>
> > > > myArray.foreach(function(obj){ return obj.className ==
> > > > 'MyProtoClass'}, function(obj) { obj.doStuff() })
>
> > > > The second one is just a little different (more Java-Like)... in this
> > > > case we would need a previous custom method on all objects that would
> > > > say if this one matches a defined parameter or not... something like
>
> > > > a.className = 'MyClass';
> > > > b.className = 'MyProtoClass';
>
> > > > a.isMyObject = function(check) { return this.className == check }
> > > > b.isMyObject = function(check) { return this.className == check }
>
> > > > myArray.foreach( 'MyProtoClass', function(obj) { obj.doStuff() })
>
> > > > and it would only apply on b.doStuff()
>
> > > > I cant tell if this would have the same utility for everyone that
> > > > would have for me... But i thing that would be very good for people
> > > > who are used to other Typed Languages...
>
> > > > Please tell me what you think about that..
>
> > > > EMoreth
--~--~---------~--~----~------------~-------~--~----~
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