js 类的this 代表的含义(张艳冲的博客)
<SCRIPT LANGUAGE="JavaScript">
<!--
function CScreen(id)
{
this.pos=0;
this.o=document.getElementByIdx_x_x(id);
this.txt=this.o.innerText;
var self=this;
this.init=function(){
// 为什么这个用self 呢 因为每一个function 相当于一类 要是写this 就是本身了
所以写self 指的是上面的类 而不是本身的类
setInterval(function(){self.knock();},300);
}
this.knock=function(){
if(this.pos>this.txt.length)
this.pos=0;
this.curTxt=this.txt.substr(0,this.pos);
this.o.innerText=this.curTxt + "_";
this.pos++;
setTimeout(function(){self.flashCursor();},150);
}
this.flashCursor=function()
{
this.o.innerText=this.curTxt;
}
}
window.onload=function (){
new CScreen("screen").init();
};
//-->
</script>
<div id="screen" style="width:300px;height:25px;background-color:#000000; color:#FFFFFF; font-size:14px; padding:2px;text-align:left">JS文字特效之打印文字效果</div>
<!--
function CScreen(id)
{
}
window.onload=function (){
};
//-->
</script>
<div id="screen" style="width:300px;height:25px;background-color:#000000; color:#FFFFFF; font-size:14px; padding:2px;text-align:left">JS文字特效之打印文字效果</div>