When entered into a JavaScript console, a jQuery object appears as an array. However, it's still an instance of the jQuery object.
var j = jQuery();
=> []
console.log(j);
=> []
console.log('test with string concat: ' + j);
=> test with string concat: [object Object]
j instanceof Array
=> false
j instanceof jQuery
=> true
How could one duplicate this with their own object?
--------- EDIT ---------
Thanks to ZER0 for figuring it out. Here's some example code to create an object that works just like jQuery in the console:
var Foo = function() {
this.splice = Array.prototype.splice;
Array.prototype.push.apply(this, arguments);
return this;
}
var f = new Foo();
=> []
console.log(f);
=> []
console.log('test with string concat: ' + f);
=> test with string concat: [object Object]
f instanceof Array
=> false
f instanceof Foo
=> true
Very cool.
jQuery() instanceof Arrayreturns false). However, I'd like it to appear as an array in the console.