Skip to content

Commit ac37365

Browse files
committed
Core: Warn and fill jQuery.isArray
Fixes jquery#220
1 parent 9e3dfcb commit ac37365

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/core.js

+9-2
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 ),
@@ -89,6 +89,13 @@ jQuery.isNumeric = function( val ) {
8989
return oldValue;
9090
};
9191

92+
migrateWarnFunc( jQuery, "isArray",
93+
function( a ) {
94+
return Array.isArray( a );
95+
},
96+
"jQuery.isArray is deprecated; use Array.isArray"
97+
);
98+
9299
migrateWarnFunc( jQuery, "unique", jQuery.uniqueSort,
93100
"jQuery.unique is deprecated; use jQuery.uniqueSort" );
94101

test/core.js

+11
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ test( "jQuery.expr.pseudos aliases", function( assert ) {
275275

276276
} );
277277

278+
QUnit.test( "jQuery.isArray", function( assert ) {
279+
assert.expect( 4 );
280+
281+
expectWarning( "isArray", 1, function() {
282+
assert.equal( jQuery.isArray( [] ), true, "empty array" );
283+
assert.equal( jQuery.isArray( "" ), false, "empty string" );
284+
assert.equal( jQuery.isArray( jQuery().toArray() ), true, "toArray" );
285+
} );
286+
287+
} );
288+
278289
TestManager.runIframeTest( "old pre-3.0 jQuery", "core-jquery2.html",
279290
function( assert, jQuery, window, document, log ) {
280291
assert.expect( 1 );

warnings.md

+6
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,9 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58
199199
**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.
200200

201201
**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 )`.
202+
203+
### JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray
204+
205+
**Cause:** Older versions of JavaScript made it difficult to determine if a particular object was a true `Array`, so jQuery provide a cross-browser function to do the work. The browsers supported by jQuery 3.0 all provide `Array.isArray(obj)` for this purpose.
206+
207+
**Solution**: Replace any calls to `jQuery.isArray` with `Array.isArray`.

0 commit comments

Comments
 (0)