-1
A
回答
3
可以覆蓋的setTimeout和setInterval和日期:
function TimeMachine(timescale,code){
timescale=timescale || 0.1;//ten times faster
var context=Object.create(window);
//setTimeout
context.setTimeout=var setTimeout=function(callb,time){
window.setTimeout(callb,time*timescale);
};
//setInterval
context.setInterval=var setInterval=function(callb,time){
window.setInterval(callb,time*timescale);
};
//Date TODO:resolve timestrings
var now=new window.Date().getTime();
window.setInterval(function(){now+=1/timescale;},1);
context.Date=var Date=function(){
this.getTime=function(){
return now;
};
}
//create Scope with new window
(function(window){
eval("("+code+")()");
})(context);
};
使用這樣的:
TimeMachine(0.1,function(){
//execute in time machines context
setInterval(function(){alert("10 seconds passed");},10000);//10secs -> 1sec
//even this should work:
window.setTimeout(function(){alert("test")},1000);
});
香港專業教育學院建立了一個時間機器:0
參考文獻: http://www.instructables.com/id/How-to-Build-a-Time-Machine-Vortex-Distortion-Spa/
0
在這裏,我創建了一個函數,當有兩個參數。第一個參數是現實世界時間,第二個參數是它對應的虛擬時間。
$v_time(1000,100); // Maps 1 second of real world as 100ms in virtual world
使用兩個參數調用函數來映射它們並創建虛擬時間世界。
$v_time(60000) // returns virtual world time corresponding to real world 60 sec;
現在,只要你需要虛擬時間調用該函數與你想要的時間。
$v_time=function (rel_time,vir_time) {
if(vir_time) $v_time.offset
= (Math.min(rel_time,vir_time)
/Math.max(rel_time,vir_time));
return rel_time*$v_time.offset;
}
$v_time(1000,100); // Maps 1sec of real world as 100ms of virtual world
setTimeout(function(){
console.log('hello');
},$v_time(10000)); // 10sec of real world will return 1s of virtual world.
做10分鐘真實世界的虛擬世界1秒
$v_time(10*60*1000,1000);
現在叫$v_time(your_time);
相關問題
- 1. 如何讓ntp時間從通過javascript
- 2. 如何讓PHPUnit + Selenium運行得更快?
- 3. 如何讓doxygen跑得更快?
- 4. 如何讓minepy.MINE跑得更快?
- 5. 如何讓DTW跑得更快?
- 6. 讓循環和空間計算更快?
- 7. 讓Haskell代碼更快更快
- 8. 得到兩者之間的經過時間的javascript日期
- 9. Javascript:哪個'時間處理'功能更快?
- 10. JavaScript:requestAnimateFrame獲得更快
- 11. 讓MediaPlayer反應更快?
- 12. 讓Zend-Framework運行更快
- 13. 什麼讓hashmaps更快?
- 14. 讓ExecuteBatch執行更快
- 15. 如何讓UNION ALL更快?
- 16. 讓AVD工作更快
- 17. 通過編譯加快編譯時間
- 18. 每秒更新javascript時間
- 19. 如何讓我的rexml/nokogiri腳本運行得更快
- 20. 在lua問題中讓對象移動得更快
- 21. 如何讓Matlab編譯器運行得更快?
- 22. 如何讓這個程序運行得更快?
- 23. 如何讓我的循環在R中運行得更快?
- 24. 有沒有辦法讓我的Python程序運行得更快?
- 25. 如何讓我的虛擬機運行得更快?
- 26. 如何讓這個SQL腳本運行得更快?
- 27. Android詞典TreeSet更快加載時間
- 28. css sprite Img的加載時間更快?
- 29. 快速更換tzinfo日期時間
- 30. 如何讓YUI更輕更快?
A排序所有的延遲你的js呢? –
你需要什麼? – akuhn
javascript是由Brenden Eich編寫的,而不是HG Wells –