jquery core: fixed makeArray to recognize the window (has length)
test runner: updated the tests for makeArray
This commit is contained in:
parent
25f9974cee
commit
508b1e2432
10
src/core.js
10
src/core.js
|
@ -1114,13 +1114,15 @@ jQuery.extend({
|
|||
makeArray: function( array ) {
|
||||
var ret = [];
|
||||
|
||||
if( array != undefined )
|
||||
//strings and functions also have 'length'
|
||||
if( array.length != undefined && !array.split && !array.call )
|
||||
for( var i = array.length; i; )
|
||||
if( array != undefined ){
|
||||
var i = array.length;
|
||||
//the window, strings and functions also have 'length'
|
||||
if( i != undefined && typeof array == 'object' && array != window )
|
||||
while( i )
|
||||
ret[--i] = array[i];
|
||||
else
|
||||
ret[0] = array;
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
|
|
@ -1563,7 +1563,7 @@ test("contents()", function() {
|
|||
});
|
||||
|
||||
test("$.makeArray", function(){
|
||||
expect(11);
|
||||
expect(13);
|
||||
|
||||
equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
|
||||
|
||||
|
@ -1577,14 +1577,18 @@ test("$.makeArray", function(){
|
|||
|
||||
equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
|
||||
|
||||
equals( typeof $.makeArray( true )[0], "boolean", "Pass makeArray a boolean" );
|
||||
equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
|
||||
|
||||
equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" );
|
||||
|
||||
equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
|
||||
|
||||
equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodeson array" );
|
||||
equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" );
|
||||
|
||||
//function (tricky, they have length)
|
||||
//function, is tricky as it has length
|
||||
equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
|
||||
//window, also has length
|
||||
equals( $.makeArray(window)[0], window, "Pass makeArray the window" );
|
||||
|
||||
equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
|
||||
});
|
Loading…
Reference in a new issue