jQuery objects act like arrays without polluting native prototypes. How is this achieved?
I know it\'s not just objects with numeric keys - so perhaps it\'s just a m
Look in jquery code (development), line 139:
// Force the current matched set of elements to become
// the specified array of elements (destroying the stack in the process)
// You should use pushStack() in order to do this, but maintain the stack
setArray: function( elems ) {
// Resetting the length to 0, then using the native Array push
// is a super-fast way to populate an object with array-like properties
this.length = 0;
Array.prototype.push.apply( this, elems );
return this;
},
This is because any result of jquery queries is array.