diff --git a/src/core.js b/src/core.js index 037101c1..5529907b 100644 --- a/src/core.js +++ b/src/core.js @@ -73,10 +73,10 @@ jQuery.parseJSON = function() { jQuery.isNumeric = function( val ) { - // The jQuery 2.2.3 implementation of isNumeric + // The jQuery 2.2.3 implementation of isNumeric, using Array.isArray function isNumeric2( obj ) { var realStringObj = obj && obj.toString(); - return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0; + return !Array.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0; } var newValue = oldIsNumeric( val ), @@ -89,6 +89,13 @@ jQuery.isNumeric = function( val ) { return oldValue; }; +migrateWarnFunc( jQuery, "isArray", + function( a ) { + return Array.isArray( a ); + }, + "jQuery.isArray is deprecated; use Array.isArray" +); + migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort, "jQuery.unique is deprecated; use jQuery.uniqueSort" ); diff --git a/test/core.js b/test/core.js index 88ca3231..30d360a7 100644 --- a/test/core.js +++ b/test/core.js @@ -275,6 +275,17 @@ test( "jQuery.expr.pseudos aliases", function( assert ) { } ); +QUnit.test( "jQuery.isArray", function( assert ) { + assert.expect( 4 ); + + expectWarning( "isArray", 1, function() { + assert.equal( jQuery.isArray( [] ), true, "empty array" ); + assert.equal( jQuery.isArray( "" ), false, "empty string" ); + assert.equal( jQuery.isArray( jQuery().toArray() ), true, "toArray" ); + } ); + +} ); + TestManager.runIframeTest( "old pre-3.0 jQuery", "core-jquery2.html", function( assert, jQuery, window, document, log ) { assert.expect( 1 ); diff --git a/warnings.md b/warnings.md index 88b2779a..2013986e 100644 --- a/warnings.md +++ b/warnings.md @@ -199,3 +199,9 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58 **Cause:** The calling code has attempted to attach a `load` event to `window` after the page has already loaded. That means the handler will never run and so is probably not what the caller intended. This can occur when the event attachment is made too late, for example, in a jQuery ready handler. It can also occur when a file is loaded dynamically with jQuery after the page has loaded, for example using the `$.getScript()` method. **Solution:** If a function `fn` does not actually depend on all page assets being fully loaded, switch to a ready handler `$( fn )` which runs earlier and will aways run `fn` even if the script that contains the code loads long after the page has fully loaded. If `fn` actually does depend on the script being fully loaded, check `document.readyState`. If the value is `"complete"` run the function immediately, otherwise use `$(window).on( "load", fn )`. + +### JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray + +**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. + +**Solution**: Replace any calls to `jQuery.isArray` with `Array.isArray`.