Core: Deprecate jQuery.isArray

Fixes gh-2961
Closes gh-3278
This commit is contained in:
Manoj Kumar 2016-08-14 10:54:16 +00:00 committed by Michał Gołębiowski
parent 5b4cb0d337
commit 1b9575b9d1
13 changed files with 23 additions and 18 deletions

View File

@ -62,7 +62,7 @@ jQuery.fn.extend( {
} else if ( typeof val === "number" ) { } else if ( typeof val === "number" ) {
val += ""; val += "";
} else if ( jQuery.isArray( val ) ) { } else if ( Array.isArray( val ) ) {
val = jQuery.map( val, function( value ) { val = jQuery.map( val, function( value ) {
return value == null ? "" : value + ""; return value == null ? "" : value + "";
} ); } );
@ -173,7 +173,7 @@ jQuery.extend( {
jQuery.each( [ "radio", "checkbox" ], function() { jQuery.each( [ "radio", "checkbox" ], function() {
jQuery.valHooks[ this ] = { jQuery.valHooks[ this ] = {
set: function( elem, value ) { set: function( elem, value ) {
if ( jQuery.isArray( value ) ) { if ( Array.isArray( value ) ) {
return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
} }
} }

View File

@ -172,11 +172,11 @@ jQuery.extend = jQuery.fn.extend = function() {
// Recurse if we're merging plain objects or arrays // Recurse if we're merging plain objects or arrays
if ( deep && copy && ( jQuery.isPlainObject( copy ) || if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
( copyIsArray = jQuery.isArray( copy ) ) ) ) { ( copyIsArray = Array.isArray( copy ) ) ) ) {
if ( copyIsArray ) { if ( copyIsArray ) {
copyIsArray = false; copyIsArray = false;
clone = src && jQuery.isArray( src ) ? src : []; clone = src && Array.isArray( src ) ? src : [];
} else { } else {
clone = src && jQuery.isPlainObject( src ) ? src : {}; clone = src && jQuery.isPlainObject( src ) ? src : {};
@ -215,8 +215,6 @@ jQuery.extend( {
return jQuery.type( obj ) === "function"; return jQuery.type( obj ) === "function";
}, },
isArray: Array.isArray,
isWindow: function( obj ) { isWindow: function( obj ) {
return obj != null && obj === obj.window; return obj != null && obj === obj.window;
}, },

View File

@ -404,7 +404,7 @@ jQuery.fn.extend( {
map = {}, map = {},
i = 0; i = 0;
if ( jQuery.isArray( name ) ) { if ( Array.isArray( name ) ) {
styles = getStyles( elem ); styles = getStyles( elem );
len = name.length; len = name.length;

View File

@ -115,7 +115,7 @@ Data.prototype = {
if ( key !== undefined ) { if ( key !== undefined ) {
// Support array or space separated string of keys // Support array or space separated string of keys
if ( jQuery.isArray( key ) ) { if ( Array.isArray( key ) ) {
// If key is an array of keys... // If key is an array of keys...
// We always set camelCase keys, so remove that. // We always set camelCase keys, so remove that.

View File

@ -25,6 +25,7 @@ jQuery.fn.extend( {
} }
} ); } );
jQuery.isArray = Array.isArray;
jQuery.parseJSON = JSON.parse; jQuery.parseJSON = JSON.parse;
} ); } );

2
src/effects.js vendored
View File

@ -256,7 +256,7 @@ function propFilter( props, specialEasing ) {
name = jQuery.camelCase( index ); name = jQuery.camelCase( index );
easing = specialEasing[ name ]; easing = specialEasing[ name ];
value = props[ index ]; value = props[ index ];
if ( jQuery.isArray( value ) ) { if ( Array.isArray( value ) ) {
easing = value[ 1 ]; easing = value[ 1 ];
value = props[ index ] = value[ 0 ]; value = props[ index ] = value[ 0 ];
} }

View File

@ -17,7 +17,7 @@ jQuery.extend( {
// Speed up dequeue by getting out quickly if this is just a lookup // Speed up dequeue by getting out quickly if this is just a lookup
if ( data ) { if ( data ) {
if ( !queue || jQuery.isArray( data ) ) { if ( !queue || Array.isArray( data ) ) {
queue = dataPriv.access( elem, type, jQuery.makeArray( data ) ); queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
} else { } else {
queue.push( data ); queue.push( data );

View File

@ -17,7 +17,7 @@ var
function buildParams( prefix, obj, traditional, add ) { function buildParams( prefix, obj, traditional, add ) {
var name; var name;
if ( jQuery.isArray( obj ) ) { if ( Array.isArray( obj ) ) {
// Serialize array item. // Serialize array item.
jQuery.each( obj, function( i, v ) { jQuery.each( obj, function( i, v ) {
@ -69,7 +69,7 @@ jQuery.param = function( a, traditional ) {
}; };
// If an array was passed in, assume that it is an array of form elements. // If an array was passed in, assume that it is an array of form elements.
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
// Serialize the form elements // Serialize the form elements
jQuery.each( a, function() { jQuery.each( a, function() {
@ -115,7 +115,7 @@ jQuery.fn.extend( {
return null; return null;
} }
if ( jQuery.isArray( val ) ) { if ( Array.isArray( val ) ) {
return jQuery.map( val, function( val ) { return jQuery.map( val, function( val ) {
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
} ); } );

View File

@ -169,7 +169,7 @@ this.ajaxTest = function( title, expect, options ) {
} }
options = options || []; options = options || [];
requestOptions = options.requests || options.request || options; requestOptions = options.requests || options.request || options;
if ( !jQuery.isArray( requestOptions ) ) { if ( !Array.isArray( requestOptions ) ) {
requestOptions = [ requestOptions ]; requestOptions = [ requestOptions ];
} }

View File

@ -35,7 +35,7 @@ QUnit.assert.expectJqData = function( env, elems, key ) {
if ( elems.jquery && elems.toArray ) { if ( elems.jquery && elems.toArray ) {
elems = elems.toArray(); elems = elems.toArray();
} }
if ( !supportjQuery.isArray( elems ) ) { if ( !Array.isArray( elems ) ) {
elems = [ elems ]; elems = [ elems ];
} }

View File

@ -1161,7 +1161,7 @@ QUnit.test( "jQuery.extend(Object, Object)", function( assert ) {
assert.ok( jQuery.extend( true, {}, nestedarray )[ "arr" ] !== arr, "Deep extend of object must clone child array" ); assert.ok( jQuery.extend( true, {}, nestedarray )[ "arr" ] !== arr, "Deep extend of object must clone child array" );
// #5991 // #5991
assert.ok( jQuery.isArray( jQuery.extend( true, { "arr": {} }, nestedarray )[ "arr" ] ), "Cloned array have to be an Array" ); assert.ok( Array.isArray( jQuery.extend( true, { "arr": {} }, nestedarray )[ "arr" ] ), "Cloned array have to be an Array" );
assert.ok( jQuery.isPlainObject( jQuery.extend( true, { "arr": arr }, { "arr": {} } )[ "arr" ] ), "Cloned object have to be an plain object" ); assert.ok( jQuery.isPlainObject( jQuery.extend( true, { "arr": arr }, { "arr": {} } )[ "arr" ] ), "Cloned object have to be an plain object" );
empty = {}; empty = {};
@ -1282,7 +1282,7 @@ QUnit.test( "jQuery.extend(true,{},{a:[], o:{}}); deep copy with array, followed
result = jQuery.extend( true, {}, initial ); result = jQuery.extend( true, {}, initial );
assert.deepEqual( result, initial, "The [result] and [initial] have equal shape and values" ); assert.deepEqual( result, initial, "The [result] and [initial] have equal shape and values" );
assert.ok( !jQuery.isArray( result.object ), "result.object wasn't paved with an empty array" ); assert.ok( !Array.isArray( result.object ), "result.object wasn't paved with an empty array" );
} ); } );
QUnit.test( "jQuery.each(Object,Function)", function( assert ) { QUnit.test( "jQuery.each(Object,Function)", function( assert ) {

View File

@ -110,3 +110,9 @@ QUnit.test( "jQuery.parseJSON", function( assert ) {
assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" ); assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
} ); } );
QUnit.test( "jQuery.isArray", function( assert ) {
assert.expect( 1 );
assert.strictEqual( jQuery.isArray, Array.isArray, "Array.isArray equals jQuery.isArray" );
} );

View File

@ -128,7 +128,7 @@ QUnit.test( "jQuery.queue should return array while manipulating the queue", fun
var div = document.createElement( "div" ); var div = document.createElement( "div" );
assert.ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" ); assert.ok( Array.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" );
} ); } );
QUnit.test( "delay()", function( assert ) { QUnit.test( "delay()", function( assert ) {