我正在使用Rails應用程序。在開發過程中一切正常。然後,我開始在heroku上部署我的rails應用程序。但預編譯資產時,heroku編譯失敗。它報告了以下錯誤。heroku預編譯錯誤的JavaScript使用for..of循環
rake aborted!
remote: ExecJS::ProgramError: Unexpected token name «of», expected punc «;» (line: 15234, col: 16, pos: 937232)
remote: Error
似乎有「的」問題在我的代碼的某個地方。
我開始搜索並在javascripit文件中找到了「of」的用法,這可能是問題所在。
我已經在我的JavaScript文件一個這一段代碼,它使用一個for..of循環
$.get("/paragraphimage/showzoom/" + itemid + "/" + msslug + "/" + pid, function(data){
console.log(data);
var i = 1;
for(var zone of data){
id = Math.random()
if (i == 1){
$("#lbp-para-picture-window").append("<div id='openseadragon-" + id + "' style='width: " + zone.width + "px; height: " + zone.height + "px; margin: auto; padding-bottom: 5px;'></div>")
}
else{
$("#lbp-para-picture-window").append("<div id='openseadragon-" + id + "' style='width: " + zone.width + "px; height: " + zone.height + "px; margin: auto; padding-bottom: 5px;'></div>")
}
showOpenseadragon(id, zone);
i = i + 1
};
});
*只是爲了澄清。 data
是一個json對象數組,我試圖迭代數組中的每個json對象。
「數據」看起來是這樣的:
[
{
"scale": 0.9508716323296355,
"bottom": 1727.7337559429477,
"right": 768.3042789223455,
"top": 1586.053882725832,
"left": 168.30427892234547,
"width": 600,
"height": 141.67987321711567,
"totalW": 1622.187004754358,
"totalH": 2146.117274167987,
"aspectratio": 1.3229777256740913,
"xcomp": 0.10375146541617819,
"ycomp": 0.9777256740914418,
"heightcomp": 0.0873388042203986,
"widthcomp": 0.3698710433763189,
"image_url": {
"scheme": "http",
"authority": "images.scta.info:3000",
"userinfo": null,
"user": null,
"password": null,
"host": "images.scta.info",
"port": 3000,
"path": "/pp-reims/R1r.jpg",
"query": null,
"fragment": null
}
},
{
"scale": 0.9508716323296355,
"bottom": 1038.351822503962,
"right": 1347.3851030110934,
"top": 167.35340729001584,
"left": 747.3851030110935,
"width": 600,
"height": 870.998415213946,
"totalW": 1622.187004754358,
"totalH": 2146.117274167987,
"aspectratio": 1.3229777256740913,
"xcomp": 0.46072684642438455,
"ycomp": 0.10316529894490033,
"heightcomp": 0.536928487690504,
"widthcomp": 0.3698710433763189,
"image_url": {
"scheme": "http",
"authority": "images.scta.info:3000",
"userinfo": null,
"user": null,
"password": null,
"host": "images.scta.info",
"port": 3000,
"path": "/pp-reims/R1r.jpg",
"query": null,
"fragment": null
}
}
]
的RubyMine也不會像這樣...循環的,並強調它是錯的。
我開始尋找這件事:
爲...的似乎是可以接受的代碼,但實驗
我以爲我可以改變這對...英寸但是,因爲...做了一些稍微不同的事情,並且似乎也被貶低了。 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for_each...in)
所以,問題:
是很可能,這for...of
是對Heroku的預編譯錯誤的原因是什麼?
如果是這樣,爲什麼我的本地機器支持它,而Heroku不支持它。
最後,我應該如何更改上面的JavaScript代碼,以便Heroku成功預編譯資源?