If you do console.log($(\'some selector\'))
in the browser, it returns what looks like an array (first line):
You make your object inherit Array
using the prototype, like so:
function SomeType() {
this.push(16);
}
SomeType.prototype = [];
SomeType.prototype.constructor = SomeType; // Make sure there are no unexpected results
console.log(new SomeType()); // Displays in console as [16]
And, of course, all jQuery objects are instances of the jQuery
function/constructor, so that's how jQuery does it. As a bonus, because of the inheritance, you get all the methods from Array
, and the indexing that comes with it too!