For some time no it's bothering the way we have to add methods to
elements.

<pre>
Element.addMethods({
  foo: function(element){
     element = $(element);
     // some magic here
  }
});
</pre>

in every Element.Methods method there is element = $(element); I
understand why is done this way and see the benefits from that. But
for me is more natural to use something like MooTools
Element.implement

<pre>
Element.implement({
  foo: function(){
     // this == $(element)
     // some magic here
  }
});
</pre>

I haven't done advanced testing about the performance of such
approach. But on first glance if it should preform better than current
(especially in IE). The current implementation use Function#methodize
when attach the function to Element prototype (or to every extended
element,  depends on the browser features). + Even if we call foo
through $(element).foo, one "useless" $ will be called (witch at best
will call only one Prototype.K), but still.
If we use Element#implement the direct function will be attached to
the element, and a wrapper will be added to the Element for "static"
calls. In my application I mostly use $(element).method, so increasing
the performance here will be most needed. Of course for Element.foo it
will use wrapper, and will be a little slower, but there could be
added validations and other useful things in the wrapper, witch now
couldn't be added. + they will be defined once and settled in Element.
And of course the code will be cleaner.

Wrappers for Element.foo could be as simple as or some sort of

<pre>
for(var name in methods){
  Element[name] = function(element){
    return methods[name].apply($(element), Array.prototype.slice.call
(arguments, 1));
  }
}
</pre>

For current version we could have Element.implement who will be the
new style and for backward compatibility Element.addMethods to work as
it works now.
I think that the code for this could be more simple and preforment
than the current one ( the code for implementing new style + the
element methods ).

I know such flipping of a feature as old as this is nearly impossible
to come. But for Prototype 2 who knows ...

-- 
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 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

Reply via email to