The jQuery return value is Array, but the constructor is Object. as?

eg,

$(document) // [ #document ] : document object in array
typeof $(document) // "object"
$(document).constructor // function Object() { [native code] } or function (a,b) { return some function; }

If the value is an array, it must be an Array constructor.

It is not an array, like an object. because an array like an object has an array property, not like [].

How can it be?

add: If yes, then show a simple code example. as

a = ... 
console.log(a) // [ ... ]
console.log(a.constructor) // function Object or something
+5
source share
2 answers

Take a look at the jQuery source. $(document)creates a cloned jQuery object of the document element, and then creates and returns an object of type array .

jQuery factory $() jQuery, (, [], ..), , , ( .pop() .reverse()).

+3

, [], JavaScript. JS , , , , ... , , , :

Object.prototype.toString.apply(myarray) === '[object Array]'
0

All Articles