No, that's not true. By using Element.addMethods(), it will be
automatically extended with $().

And the reason I am using my version of visible instead of the default
visible that comes with prototype is that I'm using the prototype
native getStyle() method so that the computation occurs on the
rendered style of the element instead of just on what is set
explicitly inside .style.display. If I set display: none; in a CSS
class declaration for an element, .visible() will return the wrong
value as the .style.display attribute is NOT set by a CSS class
attribute.

Make sense?

As proof that the Object.extend is not needed for Element.addMethods,
here is the relevant code:

1454    Element.addMethods = function(methods) {
1455      Object.extend(Element.Methods, methods || {});
1456    
1457      function copy(methods, destination, onlyIfAbsent) {
1458        onlyIfAbsent = onlyIfAbsent || false;
1459        var cache = Element.extend.cache;
1460        for (var property in methods) {
1461          var value = methods[property];
1462          if (!onlyIfAbsent || !(property in destination))
1463            destination[property] = cache.findOrStore(value);
1464        }
1465      }
1466    
1467      if (typeof HTMLElement != 'undefined') {
1468        copy(Element.Methods, HTMLElement.prototype);
1469        copy(Element.Methods.Simulated, HTMLElement.prototype, true);
1470        copy(Form.Methods, HTMLFormElement.prototype);
1471        [HTMLInputElement, HTMLTextAreaElement,
HTMLSelectElement].each(function(klass) {
1472          copy(Form.Element.Methods, klass.prototype);
1473        });
1474        _nativeExtensions = true;
1475      }
1476    }

The first thing Element.addMethods() does (on line 1455) is extend
Element.Methods with whatever methods you pass. Now all of the element
extenders built into the element getter function calls $(), $$(), etc,
all work automatically. Extending an object (Element.Methods) twice is
a lot of unnecessary overhead for JS.

-E

On 11/29/06, Marius Feraru <[EMAIL PROTECTED]> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Eric Harrison wrote:
> > I'm fairly certain that in Prototype 1.5.0_rc0 and up, you just have
> > to call Element.addMethods(). The
> > Object.extend(Element,Element.Methods); is redundant.
>
> Not really, as you wont be able to use
>   Element.foobar('element', ...)
> without it, only
>   $('element').foobar(...)
> will be available.
>
> Not a bad thing though, but it would keep many folks happy ;-)
>
> - --
> Marius Feraru
> -----BEGIN PGP SIGNATURE-----
>
> iD8DBQFFbZb6tZHp/AYZiNkRAm74AJ4lCLv87T/8YU4koiDaOeb1N1nQswCg+OnW
> ZiFx+h97mBGqCr24YG3P/zk=
> =mzU9
> -----END PGP SIGNATURE-----
>
> >
>


-- 
Eric Ryan Harrison, Developer
model13 Designs

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Ruby on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to