]> source.dussan.org Git - jquery.git/commitdiff
No ticket: Reduce .find
authorRichard Gibson <richard.gibson@gmail.com>
Sat, 20 Apr 2013 14:02:07 +0000 (10:02 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Sat, 20 Apr 2013 14:02:07 +0000 (10:02 -0400)
src/traversing.js

index 8d90d302aa46e81cdce6bcd2a9cd756e4fc2a236..4a274806ea697da89dc75834c1bb04a6ce15aa15 100644 (file)
@@ -10,11 +10,12 @@ var isSimple = /^.[^:#\[\.,]*$/,
 
 jQuery.fn.extend({
        find: function( selector ) {
-               var i, ret, self,
-                       len = this.length;
+               var i,
+                       ret = [],
+                       self = this,
+                       len = self.length;
 
                if ( typeof selector !== "string" ) {
-                       self = this;
                        return this.pushStack( jQuery( selector ).filter(function() {
                                for ( i = 0; i < len; i++ ) {
                                        if ( jQuery.contains( self[ i ], this ) ) {
@@ -24,14 +25,13 @@ jQuery.fn.extend({
                        }) );
                }
 
-               ret = [];
                for ( i = 0; i < len; i++ ) {
-                       jQuery.find( selector, this[ i ], ret );
+                       jQuery.find( selector, self[ i ], ret );
                }
 
                // Needed because $( selector, context ) becomes $( context ).find( selector )
                ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
-               ret.selector = ( this.selector ? this.selector + " " : "" ) + selector;
+               ret.selector = this.selector ? this.selector + " " + selector : selector;
                return ret;
        },