var attEventList = function(){
this.eventList = [];};attEventList.prototype = {
processTime : 20,
add : function(fn,context,arrParam){
this.eventList.push(
{
fn : fn,
context : context, //这里干嘛用的?
param : arrParam //这里干嘛用的?
}
);
},
start : function(){
var that = this;
setTimeout(function(){
that.process();
},that.processTime);
},
process : function(){
var ev = this.eventList.shift(); //这里干嘛用的?
if(!ev)
{
return;
}
ev.fn.apply(ev.context,ev.param); //这里干嘛用的?
ev = null; //这里干嘛用的,为什么要这么做?
this.start();
}
};
求指点谢谢。
processTime : 20,
add : function(fn,context,arrParam){ //
this.eventList.push(
{
fn : fn,
context : context, //函数内部的代码
param : arrParam // 这个是参数,也就是把arrParam覆值把param
}
);
}, var ev = this.eventList.shift(); //这里干嘛的?//这个是移除这个eventList的事件
//传参赋值param : arrParam //这里干嘛用的?
//传参赋值var ev = this.eventList.shift(); //这里干嘛用的?
//shift()数组的方法
//获取数组eventList的最前一个元素,并赋值给 evev.fn.apply(ev.context,ev.param); //这里干嘛用的?
//apply(o,[])函数的方法
//令ev的属性 context 调用 fn 并传参 paramev = null; //这里干嘛用的,为什么要这么做?
//释放指针
this.eventList = [];
};attEventList.prototype = {
processTime : 20,
add : function(fn,context,arrParam){
this.eventList.push(
{
fn : fn,
context : context, //往eventlist数组中推入一个对象
param : arrParam
}
);
},
start : function(){
var that = this;
setTimeout(function(){
that.process();
},that.processTime);
},
process : function(){
var ev = this.eventList.shift(); //删除数组中第一个元素,并返回这个元素
if(!ev)
{
return;
}
/* {
fn : fn,
context : context,
param : arrParam
} */
ev.fn.apply(ev.context,ev.param); //fn方法在 context上调用,ev.param为参数
ev = null; //赋值空引用
this.start();
}
};