我有一個在現代基於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