#945 ✓wont_fix
Markus Nix

Possible speed improvement for $

Reported by Markus Nix | November 25th, 2009 @ 09:02 PM

I would like to introduce a small patch to the Prototype Core, not sure,
if it is that useful but it worked for me. Thing is that mostly in lazily
programmed Objects/Classes based on Prototype people tend towards using
the $ function whenever they want to have access to a specific node,
either already extended or not. That's okay, but in a lot of scripts I have seen,
people use the $ function on and on not thinking about the specific
state of the element. I came up with a little patch, which measurably
reduced the processing time of Prototype when using several (lazy)
scripts - applied before entering the core Element.extend function.

function $( element ) {
if ( arguments.length > 1 ) {

for ( var i = 0, elements = [], length = arguments.length; i < length; i++ ) {
  elements.push( $( arguments[i] ) );
}

return elements;

}

if ( Object.isString( element ) ) {

element = document.getElementById( element );

}

// already extended? return ( !element || element.identify )? // or some other meaningful property/method

element :
Element.extend( element );

};

This is my first ticket, I hope that I respected the guidelines.

Cheers,

Markus

Comments and changes to this ticket

  • Markus Nix

    Markus Nix November 25th, 2009 @ 09:03 PM

    I'm sorry, unfortunately I broke the scripts layout...

  • Markus Nix

    Markus Nix November 25th, 2009 @ 10:14 PM

    function $(element) {
      if (arguments.length > 1) {
        for ( var i = 0, elements = [], length = arguments.length; i < length; i++ ) {
          elements.push( $( arguments[i] ) );
        }
    
        return elements;
      }
    
      if (Object.isString(element)) {
        element = document.getElementById( element );
      }
    
      return ( !element || element.identify )? // or some other meaningful property/method
        element :
        Element.extend(element);
    };
    
  • Tobie Langel

    Tobie Langel December 8th, 2009 @ 02:50 AM

    • State changed from “new” to “wont_fix”

    This is already handled inside of Element.extend. Closing as wontfix.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages