jQuery对象用console.log输出看到的很像数组是怎么实现的?

图片上传不了,老出错;就只能复制啦!
这个是我自己构造的对象,用console.log输出看到是这样;
foo.fn.foo.init{0:div,1:div,2:div,3:div,4:div,selector:"div",init:function,aouth:"jer",age:24,add:"江西"…}
jquery对象用console.log输出像一个数组;
[div,div,div,div,div,prevObject:b.fn.b.init[1],context:document,selector:"div",jquery:"1.9.1",constructor:function…]
想知道它是怎么实现的,下面是我写的源码;
(function(){
functionfoo(selector){
returnnewfoo.prototype.init(selector);
};
foo.fn=foo.prototype={
init:function(selector){
varelems=document.getElementsByTagName(selector),
len=elems.length,
i=0;
for(;ithis[i]=elems[i];
};
this.selector=selector
returnthis;
},
aouth:'jer',
age:24,
add:'江西'
};
foo.prototype.init.prototype=foo.prototype;
foo.fn.sayName=function(){
returnthis;
};
foo.fn.sayAdd=function(){
returnthis;
};
window.foo=foo;
})();
//console.log(foo);
varselects=foo('div');
console.log(selects);
芜湖不芜
浏览 697回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript