I think you misinterpreted what I was saying.  Simply "swapping" bind
for curry will certainly generate errors.

I don't really feel like explaining it and its of potentially trivial
performance results but, savor some of this syntax...

        var ele = $("container");
        var arr = $w("foo bar derka");
        var bool = arr.any(Element.hasClassName.curry(ele));
        console.log(bool);//if this throws an error, get firebug!!

...

<div id="container" class='foo'></div>

--

http://positionabsolute.net

On May 14, 5:04 pm, louis w <[email protected]> wrote:
> Thanks guys. I am going to compare the difference in processing time
> of TJ's suggestions. It will be called often (from a Form Observer).
> For now I am using this one:
>
>                         if 
> (_validate_field_classes.any(element.hasClassName.bind
> (element))) {
>
> Wasn't aware of the any function.
>
> Matt. I tried swapping bind for curry and it gave an error.
>
> On May 14, 3:32 pm, Matt Foster <[email protected]> wrote:
>
> > >     var test = ['foo', 'bar', 'foob'];
> > >     if (test.any(element.hasClassName.bind(element))) {
>
> > I believe using the non-methodized version of this method would be
> > better
>
> > Element.hasClassName.curry(element);
>
> > --
>
> >http://positionabsolute.net
>
> > On May 14, 12:30 pm, "T.J. Crowder" <[email protected]> wrote:
>
> > > Hi,
>
> > > I can think of two approaches off-hand:
>
> > > 1. Use Enumerable#include on the array of classes you want to test
> > > against, using Element#hasClassName as the iterator function (bound to
> > > the instance), e.g.:
>
> > >     var test = ['foo', 'bar', 'foob'];
> > >     if (test.any(element.hasClassName.bind(element))) {
> > >         // ...
> > >     }
>
> > > or
>
> > >     if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
> > > (element))) {
> > >         // ...
> > >     }
>
> > > (You don't need to use $A() around array literals.)
>
> > > 2. Use $w on the class name to get an array of the individual class
> > > names, then use Enumerable#any on that, passing in Enumerable#include
> > > on the array you want to test against as the #any iterator.  Something
> > > like this:
>
> > >     var test = ['foo', 'bar', 'foob'];
> > >     if ($w(element.className).any(test.include.bind(test))) {
> > >         log("true");
> > >     }
>
> > > (Both of those bits of code are untested.)
>
> > > But if this is going to be happening a lot (a tight loop, or a
> > > mouseover handler, etc.), check the runtime cost of each of these by
> > > going under the covers.
>
> > > FWIW,
> > > --
> > > T.J. Crowder
> > > tj / crowder software / com
> > > Independent Software Engineer, consulting services available
>
> > > On May 13, 7:34 pm, louis w <[email protected]> wrote:
>
> > > > I have an array containing a number of strings. I would like to
> > > > continue exucuting my script only if an item has ANY/ALL of the
> > > > strings assigned as a class name.
>
> > > > $A(['foo', 'bar', 'foob']);
>
> > > > Is there an elegant want to do this without having to loop through the
> > > > items?
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to