JS模擬多線程
runNum : 0, //當(dāng)前正式運(yùn)行的線程數(shù)
maxNum : 10, //最大同時(shí)執(zhí)行的線程數(shù) -1表示不限
commandList : new Array(),
start : function(){
//window.status = this.runNum;
if(this.maxNum != -1 && this.runNum >= this.maxNum){
return;
}
if(this.commandList.length <= 0){
this.runNum = 0;
return false;
}
this.runNum++;
var _this =this;
var tFun = function(){
if(!_this.commandList[0]) return;
var command = _this.commandList[0].shift();
command.apply(_this,_this.commandList[0].concat(
function(){ //alert(2)
if(_this.runNum > 0)_this.runNum--;
setTimeout(function(){_this.start.apply(_this)},1);
}));
_this.commandList.shift();
}
setTimeout(tFun,1);
setTimeout(function(){_this.start.apply(_this)},10);
}
}
<script src="prototype.js"></script>
<script type="text/javascript" defer="defer">
function test(obj,info,callback){
callback = callback || new Function();
new Ajax.Request('test.xml',{method:'get',
onSuccess:function(o){
$(obj).innerHTML += info + '完成<br>';
callback('完成');
},
onFailure : function(o){
$(obj).innerHTML += info + '失敗<br>';
callback('失敗');
},
onComplete : function(o){
document.body.scrollTop = 9999;
}
});
}
var Thread = {
runNum : 0, //當(dāng)前正式運(yùn)行的線程數(shù)
maxNum : 5, //最大同時(shí)執(zhí)行的線程數(shù) -1表示不限
commandList : new Array(),
start : function(){
//window.status = this.runNum;
if(this.maxNum != -1 && this.runNum >= this.maxNum){
return;
}
if(this.commandList.length <= 0){
this.runNum = 0;
return false;
}
this.runNum++;
var _this =this;
var tFun = function(){
if(!_this.commandList[0]) return;
var command = _this.commandList[0].shift();
command.apply(_this,_this.commandList[0].concat(
function(){ //alert(2)
if(_this.runNum > 0)_this.runNum--;
setTimeout(function(){_this.start.apply(_this)},1);
}));
_this.commandList.shift();
}
setTimeout(tFun,1);
setTimeout(function(){_this.start.apply(_this)},10);
}
}
for(var i = 0; i < 100 ; i++){
Thread.commandList.push(new Array(test,document.body,i+1));
};
Thread.start();
</script>
<body>
</body>
- JS模擬的Map類實(shí)現(xiàn)方法
- js模擬點(diǎn)擊事件實(shí)現(xiàn)代碼
- js模擬滾動(dòng)條(橫向豎向)
- js模擬點(diǎn)擊以提交表單為例兼容主流瀏覽器
- javascript用DIV模擬彈出窗口_窗體滾動(dòng)跟隨
- javascript模擬滾動(dòng)條實(shí)現(xiàn)代碼
- JS組件Bootstrap實(shí)現(xiàn)下拉菜單效果代碼
- 基于AngularJs + Bootstrap + AngularStrap相結(jié)合實(shí)現(xiàn)省市區(qū)聯(lián)動(dòng)代碼
- JS組件Bootstrap Table使用實(shí)例分享
- 三級(jí)下拉菜單的js實(shí)現(xiàn)代碼
- JS實(shí)多級(jí)聯(lián)動(dòng)下拉菜單類,簡(jiǎn)單實(shí)現(xiàn)省市區(qū)聯(lián)動(dòng)菜單!
- Js點(diǎn)擊彈出下拉菜單效果實(shí)例
- JS模擬bootstrap下拉菜單效果實(shí)例
相關(guān)文章
HTML Table 空白單元格補(bǔ)全的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄狧TML Table 空白單元格補(bǔ)全的簡(jiǎn)單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10
localStorage的黑科技-js和css緩存機(jī)制
本文主要介紹了localStorage的黑科技-js和css緩存機(jī)制的相關(guān)知識(shí),具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-02-02
echarts實(shí)現(xiàn)3d柱狀圖的2種方式舉例
echarts3D效果柱狀圖的實(shí)現(xiàn),這個(gè)太難了,我花了兩天終于調(diào)成我想要的效果啦,要是官網(wǎng)上有例子就好了,太難調(diào)了,下面這篇文章主要給大家介紹了關(guān)于echarts實(shí)現(xiàn)3d柱狀圖的2種方式,需要的朋友可以參考下2023-02-02
JavaScript 5 新增 Array 方法實(shí)現(xiàn)介紹
JavaScript 5 發(fā)布有一段時(shí)間了,Array 對(duì)象新增了很多方法。但在老版本的瀏覽器上還不能使用,得益于 JavaScript 的動(dòng)態(tài)可擴(kuò)展性,我實(shí)現(xiàn)了這些方法,在此曬出來與君共勉2012-02-02
JS模擬自動(dòng)點(diǎn)擊的簡(jiǎn)單實(shí)例
這篇文章介紹了JS模擬自動(dòng)點(diǎn)擊的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-08-08

