我在这里有一个奇怪的需求,我不确定它的可行性。我只能想到如何使用线程来执行此操作(要创建另一个执行Quine函数的线程,该线程在运行脚本的同时执行Quine函数,我希望同时执行Quine并执行脚本(无需手动向各处添加警报!!!),但javascript没有这个功能,对吧?Javascript:同时执行和奎因
我有一些JavaScript是由一个应用程序来解释的,它具有最小的JavaScript调试功能,我的脚本正在崩溃,因为它也使用了一些只被这个应用程序理解的语句我无法在Firefox或Internet Explorer中调试它,因为它们无法处理这些自定义语句。我希望能够实现的一个程序可以模拟另一个程序,但也可以执行它自己的功能。为了说明我有一个名为hello.js的脚本,输出“Hello World!”100次,当提供给应用程序时,它解释了这一点,但是在某些时候已经崩溃了,但我无法说出为什么,何时何地因为有限的调试功能。
function main(){
for(var i=0; i<100; i++){
alert('Hello World!\n');
}
}
然后我想有一个脚本,我可以传递给应用程序,而不是将假装是上面的脚本,但也警惕在执行每个语句之前。我可以这样做:
function main(){
alert('main()')
for(var i=0; i<100; i++){
alert("alert('Hello World!\n');");
alert('Hello World!\n');
}
}
但是我相信你可以看到如何为一个长期的计划这将是一项艰巨的任务。相反,我想做一个程序,可以这样执行:
function main(){
var text = loadJSScript("C:\\Script\\Hello.js"); //Loads a text/javascript file line by line into an array
for(var i=0; i<text.length; i++){
var statement = text[i];
alert("Line Number: " + i + " Statement: " + statement); //Output the line number and statement before executing
execute(statement); //A function that executes the statement from the other file (as if a separate thread)
}
}
http://articles.sitepoint。com/article/multi-threading-javascript 一个关于多线程Javascript的文章的例子,探索使用setInterval(类似于setTimeout但是重复发生) 但是如果可能的话,AJAX看起来更好。 – 2010-09-01 13:13:05
干杯我会看看这个,并尝试网络工作者。 – 2010-09-01 13:34:50