Created
April 29, 2011 00:24
-
-
Save kflorence/947623 to your computer and use it in GitHub Desktop.
isArrayLike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( jQuery ) { | |
// Determines if we can treat an object like an array. | |
var isArrayLike = function( obj ) { | |
var length; | |
// Supports arrays, jQuery objects, nodeLists and HTMLCollections | |
// Should also support function arguments, but there is no cross-browser way... | |
return obj && ( obj instanceof jQuery || ( typeof obj === "object" && | |
!jQuery.isWindow( obj ) && ( typeof ( length = obj.length ) === "number" && | |
( obj.item && ( obj.namedItem || jQuery.isFunction( obj.item ) ) ) ) || jQuery.isArray( obj ) ) ); | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://jsfiddle.net/kflorence/JUxZA/