I appreciate the quick, honest and accepting responses on this forum.
I'm still debating whether to convert my ~2005 library to use
MooTools, or simply update it to recent changes myself. Some things
make me want to move to MooTools, like when I look at all the element
size/position fixups I wrote that are probably out of date with
today's browsers. But some of the core content processing makes me
like what I have. Here's my old hasClass():

        /**Determines whether the given element has the given class, using
DOM methods. Multiple class names are supported.
        @param element The element that should be checked for class.
        @param className The name of the class for which to check, or a
regular expression if a match should be found.
        @return true if one of the element's class names equals the given
class name.
        */
        hasClass:function(element, className)
        {
                var classNamesString=element.getAttribute("class");     //get 
the
element's class names
                var classNames=classNamesString ? classNamesString.split(/\s/) :
EMPTY_ARRAY;    //split out the class names
                return className instanceof RegExp ?
classNames.containsMatch(className) :
classNames.contains(className); //return whether this class name is
one of the class names
        },

1. I note that the MooTools version uses a very brute-force string
based approach. That is, it "cleans" the string (using a regular
expression to change whitespace to spaces), then trims the string,
then fixes up the original string with surrounding spaced, then adds a
space to the test string, and then (finally!) walks through the string
with indexOf(). Since MooTools already starts the whole process with a
regex, anyway, isn't the above approach more efficient?

2. More importantly, I need to check against regular expressions. How
open would MooTools be to adding regex capability to methods such as
this?

Thanks,

Garret

P.S. I haven't looked at my code in about five years. I'm not sure why
I didn't just bind hasClass() to Element.prototype. Any ideas? Did IE6
or some similar nightmare prevent adding Element methods or something?

Reply via email to