模拟线程Timer(JS)
2015-05-15 19:30
274 查看
<script language="JavaScript" type="text/javascript">
var Timer = function(runnable){
this._runnable=(runnable=(runnable||this));
this._runFunc0 = function(){
runnable['run'].apply(runnable);
}
this._interval = 1000;
};
Timer.prototype.run = function(){
if(this._time_count==null){
this._time_count=0;
};
document.body.innerHTML=document.body.innerHTML+'Timer: '+(this._time_count++)+'<BR>'
};
Timer.prototype.start = function()
{
this._timeId = window.setInterval(this._runFunc0, this._interval);
};
Timer.prototype.sheep = function(st)
{
var sheepTime = st || 500;
window.clearTimeout(this._timeId);
var _this = this;
window.setTimeout((function(){_this['start'].apply(_this);}), sheepTime );
};
var t = new Timer();
t.start();
</script>
var Timer = function(runnable){
this._runnable=(runnable=(runnable||this));
this._runFunc0 = function(){
runnable['run'].apply(runnable);
}
this._interval = 1000;
};
Timer.prototype.run = function(){
if(this._time_count==null){
this._time_count=0;
};
document.body.innerHTML=document.body.innerHTML+'Timer: '+(this._time_count++)+'<BR>'
};
Timer.prototype.start = function()
{
this._timeId = window.setInterval(this._runFunc0, this._interval);
};
Timer.prototype.sheep = function(st)
{
var sheepTime = st || 500;
window.clearTimeout(this._timeId);
var _this = this;
window.setTimeout((function(){_this['start'].apply(_this);}), sheepTime );
};
var t = new Timer();
t.start();
</script>
相关文章推荐
- JS 模拟线程实现sleep
- 用js模拟线程 是否可以实现?
- (9)java5的线程【锁lock】与【读写锁_以及模拟缓存(妙用)】技术
- js模拟select
- C# 线程Timer的Change方法解释
- Java线程锁_模拟失效时修改值
- TimerTask()中调用TextView.setText报错原因(非UI线程中 不能访问UI组件)
- 用js模拟java的StringBuffer, 主要提高组装字符窜的效率
- JS模拟Alert与Confirm对话框
- weblogic stuck线程模拟
- js模拟select下拉菜单控件的代码
- js模拟marquee效果收集
- jquery.timer.js的使用
- js-模拟easyui-datagrid表格各行选中事件-实现逻辑
- java中使用线程实现Timer(定时器)原理和源码
- JavaScript_js模拟键盘输入
- Android 主线程handler 和子线程handler的通讯实例,图灵机器人(本地模拟回复,暂时没有网络请求)
- 20170914 js模拟事件,什么click()都是伪模拟
- js线程
- js 模拟右键菜单