Skip to content

Commit

Permalink
Core: Warn and fill jQuery.isArray
Browse files Browse the repository at this point in the history
Fixes #220
Closes #245
  • Loading branch information
dmethvin committed Jan 26, 2017
1 parent 6161d2b commit c73559f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand All @@ -92,6 +92,13 @@ jQuery.isNumeric = function( val ) {
migrateWarnFunc( jQuery, "holdReady", jQuery.holdReady,
"jQuery.holdReady is deprecated" );

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" );

Expand Down
11 changes: 11 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,17 @@ QUnit.test( "jQuery.holdReady (warn only)", 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 );
Expand Down
6 changes: 6 additions & 0 deletions warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,9 @@ See jQuery-ui [commit](https://github.com/jquery/jquery-ui/commit/c0093b599fcd58
**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.

**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.

### 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`.

0 comments on commit c73559f

Please sign in to comment.