我有一个在现代基于webkit的浏览器(http://montecarlo-tester.appspot.com/)中工作得很好的web应用程序。基本上它使用webworker从服务器获取数据,然后在执行一些计算后将其发回。web工作人员在webkit中的行为与Firefox不同的地方
它在Chrome/Safari(控制台中没有错误)中工作得很好,但是当我尝试在Firefox中使用它时,它没有。我推断,不知何故,在Firefox中未正确设置变量“迭代”。不幸的是,Firefox缺少一个调试器(对于网络工作者),而且JavaScript具有功能范围,因此很难确定问题的出处。我已为我的网络工作者的JavaScript代码,我想知道是否有人能指出我哪里错了:
importScripts('/static/js/mylibs/jquery.hive.pollen-mod.js');
$(function (data) {
main();
//while(main());
close();
});
function main() {
//make an ajax call to get a param
var iterations//value will be set by server response
var key//key of the datastore object
var continueloop = true;
p.ajax.post({
url:'/getdataurl',
dataType: "json",
success: function(responseText){
if (responseText === null) {
var workermessage = {
"log":"responseText is null. Either the server has issues or we have run out of stuff to compute."
};
$.send(workermessage);
continueloop = false;
}
iterations = responseText.iterationsjob;
key = responseText.key;
}
});
if (continueloop === false) {
return false;
}
//here is where I think the problems begin. In chrome/safari, iterations = 1000.
//In Firefox however, iterations = null. As a result, everything after that does not work.
var i,x,y,z;
var count = 0;
var pi;
start = new Date();
for (i=0;i<iterations;i++) {
x = Math.random();
y = Math.random();
z = x*x+y*y;
if(z<=1.0){
count++;
}
}//end for loop
pi = count/(iterations)*4.0;
end = new Date();
result = {
"estimated_pi":pi,
"num_iter":iterations,
"duration_ms":end.valueOf()-start.valueOf(),
"key":key
};
//send results to the server
p.ajax.post({
url: "/resultshandler",
dataType:'json',
data: result,
success: function()
{
//do nothing!
}
});
$.send(result);
return true;//persists the loop
}
“不幸的是,火狐缺乏一个调试器”您是否尝试过[萤火虫](http://getfirebug.com)? – 2011-12-16 01:03:37
在`var iterations`和`var key`的注释之前在变量名后面加分号会有什么区别吗? – jfriend00 2011-12-16 01:04:02