我試圖做一個setTimeout,我將變量傳遞給setTimeout()內被調用的函數。經過一些初步的失敗,然後使用谷歌我發現一個網站,描述如何使用閉包做到這一點。我幾乎跟着例子,但我不斷收到一條錯誤消息:經過參數列表javascript關閉錯誤
此錯誤消息正在呼籲setTimeout的,但據我可以告訴一切被關閉
缺失)。任何幫助,將不勝感激:
var textureAtlas = new Image()
function init() {
textureAtlas.src = "images/textureatlast1.png";
var textureAtlasCoords = new Array("0,0", "100,0", "200,0", "300,0", "400,0", "500,0", "600,0");
var canvas = document.getElementById('textureAtlas');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
for(var c=0; c<textureAtlasCoords.length; c++) {
var thisCoord = textureAtlasCoords[c];
var thisCoordSplit = thisCoord.split(",");
var thisX = thisCoordSplit[0];
var thisY = thisCoordSplit[1];
var a = setTimeout(animate(){myFunction(ctx, textureAtlas, thisX, thisY); ctx=null, textureAtlas=null, thisX=null, thisY=null},1000);
}
} else {
alert("Looks like your browser doesn't support HTML5");
}
}
function animate() {
ctx.drawImage(thisImg,thisX,thisY, 1024, 451, 0, 0, 1024, 451);
}
在setTimeout調用,是「有生命的」一個錯字?或者你是否想要調用'animate'? – Lobstrosity
動畫後的「{...}」是什麼? –
如果它幫助我與這裏給出的示例工作:http://www.makemineatriple.com/2007/10/passing-parameters-to-a-function-called-with-settimeout – PruitIgoe