I would do that with an Array.filter().each().
Using two functions as you want to do is too specific to your problem
in my opinion.

If you are searching for an Array.filter, you can use the extension
which I've posted on my blog some days ago:


EMoreth 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 

Reply via email to