Nov 13, 2010

jQuery object is an array like object

jQuery object is not an Array object, but it looks like an array. The following code how this is implemented?

var o = {"0":1, "1": 2, length:2};
var a = [].slice.call(o, 0);
alert(a); // 1, 2


//or you can do this
var o = {}
o[0] = 1;
o.length = 1;
o[1] = 2;
o.length = 2;
var a = [].slice.call(o, 0);
alert(a); // 1, 2

//or you can do this
var o = {};
[].push.call(o, 1);
[].push.call(o, 2);
var a = [].slice.call(o, 0);
alert(a); // 1, 2