Wouldn't it be possible to have the better of the two worlds with
something like this:

SafeElement=Class.create();
for (e in Element.Methods)
{
 
SafeElement[e]=Element.Methods[e].wrap(function(originalFunction,element)
  {
        var args;

        element = $(element);
        if (!element)
        {
            return undefined;
        }
        args = $A(arguments);
        args.shift();
        args[0] = element; // We've already looked it up, save doing
it again
        return originalFunction.apply(this, args);
  });
}

This way, we would have a new "SafeElement" class with all methods of
Element except they have a safe behavior.
So you can use Element.hide('xx') if you're sure 'xx' element exists
or SafeElement.hide('xx') if you're not or if you're ok with the
runtime overhead.

This may perhaps be added to official prototype since it could be
utile to many persons, and would have a very marginal impact when the
library is loaded.
What do you think?

Eric

NB: This is an untested example, but I am pretty confident it can be
tweaked until it actually works :o)
--~--~---------~--~----~------------~-------~--~----~
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-scriptaculous@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-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to