Skip to content

Commit c73559f

Browse files
committed
Core: Warn and fill jQuery.isArray
Fixes #220 Closes #245
1 parent 6161d2b commit c73559f

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/core.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ jQuery.parseJSON = function() {
7373

7474
jQuery.isNumeric = function( val ) {
7575

76-
// The jQuery 2.2.3 implementation of isNumeric
76+
// The jQuery 2.2.3 implementation of isNumeric, using Array.isArray
7777
function isNumeric2( obj ) {
7878
var realStringObj = obj && obj.toString();
79-
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
79+
return !Array.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
8080
}
8181

8282
var newValue = oldIsNumeric( val ),
@@ -92,6 +92,13 @@ jQuery.isNumeric = function( val ) {
9292
migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
9393
"jQuery.holdReady is deprecated" );
9494

95+
migrateWarnFunc( jQuery, "isArray",
96+
function( a ) {
97+
return Array.isArray( a );
98+
},
99+
"jQuery.isArray is deprecated; use Array.isArray"
100+
);
101+
95102
migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
96103
"jQuery.unique is deprecated; use jQuery.uniqueSort" );
97104

test/core.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,17 @@ QUnit.test( "jQuery.holdReady (warn only)", function( assert ) {
284284
} );
285285
} );
286286

287+
QUnit.test( "jQuery.isArray", function( assert ) {
288+
assert.expect( 4 );
289+
290+
expectWarning( "isArray", 1, function() {
291+
assert.equal( jQuery.isArray( [] ), true, "empty array" );
292+
assert.equal( jQuery.isArray( "" ), false, "empty string" );
293+
assert.equal( jQuery.isArray( jQuery().toArray() ), true, "toArray" );
294+
} );
295+
296+
} );
297+
287298
TestManager.runIframeTest( "old pre-3.0 jQuery", "core-jquery2.html",
288299
function( assert, jQuery, window, document, log ) {
289300
assert.expect( 1 );

warnings.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,9 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58
205205
**Cause:** The `jQuery.holdReady()` method has been deprecated due to its detrimental effect on the global performance of the page. This method can prevent all the code on the page from initializing for extended lengths of time.
206206

207207
**Solution:** Rewrite the page so that it does not require all jQuery ready handlers to be delayed. This might be accomplished, for example, by late-loading only the code that requires the delay when it is safe to run. Due to the complexity of this method, jQuery Migrate does not attempt to fill the functionality. If the underlying version of jQuery used with jQuery Migrate no longer contains `jQuery.holdReady()` the code will fail shortly after this warning appears.
208+
209+
### JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray
210+
211+
**Cause:** Older versions of JavaScript made it difficult to determine if a particular object was a true `Array`, so jQuery provided a cross-browser function to do the work. The browsers supported by jQuery 3.0 all provide `Array.isArray(obj)` for this purpose.
212+
213+
**Solution**: Replace any calls to `jQuery.isArray` with `Array.isArray`.

0 commit comments

Comments
 (0)