]> source.dussan.org Git - jquery.git/commitdiff
jquery core: Patch from #2619 applied, making makeArray more flexible and faster...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 24 Apr 2008 21:23:36 +0000 (21:23 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 24 Apr 2008 21:23:36 +0000 (21:23 +0000)
src/core.js
test/unit/core.js

index 6308a99929ed0744d427e2c96d6deb43ba54847f..072642f6304ad3c9658ad928d4028577fbe07b42 100644 (file)
@@ -1123,12 +1123,13 @@ jQuery.extend({
        makeArray: function( array ) {
                var ret = [];
 
-               // Need to use typeof to fight Safari childNodes crashes
-               if ( array.constructor != Array )
-                       for ( var i = 0, length = array.length; i < length; i++ )
-                               ret.push( array[ i ] );
-               else
-                       ret = array.slice( 0 );
+               if( array != undefined )
+                       //strings and functions also have 'length'
+                       if( array.length != undefined && !array.split && !array.call )
+                               for( var i = array.length; i; )
+                                       ret[--i] = array[i];
+                       else
+                               ret[0] = array;
 
                return ret;
        },
index 412ba39c354bde17d7f03d3c9dde1abac9e12247..b79b8cb21d0172965014dd300f64ba5f2d5240e0 100644 (file)
@@ -1562,7 +1562,7 @@ test("contents()", function() {
        equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
 });
 
-test("makeArray(#2619)", function(){
+test("$.makeArray", function(){
        expect(11);
        
        equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );