class jQuery{
// 构造函数 获取想要的demo节点 返回的对象是伪数组
constructor(selector){
const elements = document.querySelectorAll(selector);
const length = elements.length;
for(let i= 0;i<length;i++){
//把获取到的所有对象挂载到对象
this[i] = elements[i]
}
this.length = length;
this.selerctor= selector;
return this; //如果不写默认返回this
}
//根据下标获取对应的demo 节点
get(index){
return this[index];
}
// 遍历伪数组使用回调函数对demo进行操作
each(fn){
for(let i =0;i< this.length; i++){
const elem = this[i];
fn(elem);
}
}
// 监听事件对demo的事件进行响应
on(type,fn){
this.each(elem=>{
elem.addEventListener(type,fn,false);
})
}
}
// 插件
jQuery.prototype.showInfo = function(info){
consloe.log(info)
}
//扩展性
class childJquery extends jQuery{
constructor(selector){
super(selector)
}
addclass(className){
for(let i=0; i < this.length ; i++){
const elem = this[i]
elem.className += `${className}+${i}`
console.log(elem)
}
}
}