I always thought that the jQuery function $returns an array with jQuery methods attached to it. I want to give some examples:
Say we have an array
var arr = [1,2,3];
Then we can add our own properties:
arr.someProp = 10;
arr.someMethod = function() { ... }
After that, it arrremains an array, despite user properties:
arr instanceof Array;
So, I thought the jQuery object was something like arr(but more complex) until a recent experiment. I just run this code:
$('div') instanceof Array;
But it behaves like an array. It has a property push, a property lengththat works correctly even in this case:
var $jq = $('div');
$jq.length;
$jq.push(123);
$jq.length
Also, if you execute console.log($('div')), it will output something like this:
[<div></div>, <div></div>, <div></div>]
, jQuery , Array.prototype :
$('div').sort === Array.prototype.sort;
$('div').splice === Array.prototype.splice;
: ?
, , , , .