Timer的Class化还是失败了

本文探讨了JavaScript中Tab切换功能的实现,并尝试将定时器功能集成到Tab切换的核心类中,过程中遇到了一些挑战,如定时器无法获取类属性等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

深夜了,还在写tab切换的核心类,很想把timer集成进去,却不行。

/**
* @author edwardpro@hellodigi.com
* @copyright hellodigi.com 2007~2008
* @projectDescription provide with you a tabs changes function
*/
var tabCore=function(tabs,tabsItem){
this._tabs=$(tabs);
this._timeout=0;//默认是0
this._curitem=0;// current item means who is the current object.
this._timer;
this._tabsitemObj=$(tabs).getElementsBySelector(tabsItem);
this.dochange=function(){}
this.enabletimer=function(){
this._timer=setInterval(this.dochange,this._timeout);
};
this.disabletimer=function(){
clearInterval(this._timer);
}
this.getcurObj=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
//alert(this._curitem);
return this._tabsitemObj[this._curitem];
}; //单体执行ok
}
tabCore.prototype.addListen=function(dofunc,eventname){
//添加tab事件到主函数
for(var i=0;i<this._tabsitemObj.size();i++){
Event.observe(this._tabsitemObj[i], eventname, function(event) {
var elt = Event.element(event);
if(elt.tagName == "A"){
dofunc(elt);
}
});
}

}

tabCore.prototype.setdochange=function(dofunc){
this.dochange=function(){
this._curitem=(this._curitem+1)%this._tabsitemObj.size();
dofunc(this._tabsitemObj[this._curitem]); //调用之后却告诉我没有这个属性
};
}
tabCore.prototype.setTimer=function(timeout,func){
if(timeout){
this._timeout=timeout;
}else{
this._timeout=0;
}
this.setdochange(func);
this._timer=setInterval(this.dochange,this._timeout);

}
tabCore.prototype.test=function(){
alert(this._tabsitemObj.size());
}

看来和js的类核心有关,他的timer应该是只能接收类似静态函数的东西,唯一解释就是那个类当时并没有初始化,所以得不到属性值。不知道是方法问题还是什么。实现了半天实现了一个人家也做了的功能貌似还没有别人好用郁闷啊!!!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值