Optimized jQuery(Element) to not call jQuery() twice.
authorJohn Resig <jeresig@gmail.com>
Sat, 11 Jul 2009 13:44:44 +0000 (13:44 +0000)
committerJohn Resig <jeresig@gmail.com>
Sat, 11 Jul 2009 13:44:44 +0000 (13:44 +0000)
src/core.js

index 78f48d7..cab3b54 100644 (file)
@@ -72,10 +72,13 @@ jQuery.fn = jQuery.prototype = {
                                        }
 
                                        // Otherwise, we inject the element directly into the jQuery object
-                                       ret = jQuery( elem || null );
-                                       ret.context = document;
-                                       ret.selector = selector;
-                                       return ret;
+                                       this.length = elem ? 1 : 0;
+                                       if ( elem ) {
+                                               this[0] = elem;
+                                       }
+                                       this.context = document;
+                                       this.selector = selector;
+                                       return this;
                                }
 
                        // HANDLE: $(expr, $(...))