我有什么理由得到错误
未捕获的TypeError:inter不是函数 在movingPiece(script.js:270) 在keyboardMove(script.js:146)
在此代码中:
var inter = setInterval(function() {
draw();
b_ctx.globalCompositeOperation = "copy";
b_ctx.fillStyle = "purple";
b_ctx.beginPath();
b_ctx.arc(xcoord, y, 45, 0, Math.PI * 2, true);
b_ctx.fill();
y += 1;
if (y > endY) clearInterval(inter)
}, 25);
inter();
答案 0 :(得分:1)
inter并不是真正的功能。所以你不能称之为。它每25毫秒自动调用一次。
您收到错误是因为您正在调用它。它会自动调用。你不需要打电话或调用它。
答案 1 :(得分:0)
setInterval
不返回函数。像这样修改它。
var inter = function(){
var interVar = setInterval(function(){
draw();
b_ctx.globalCompositeOperation="copy";
b_ctx.fillStyle = "purple";
b_ctx.beginPath();
b_ctx.arc(xcoord, y, 45, 0, Math.PI*2, true);
b_ctx.fill();
y+=1;
if(y>endY) clearInterval(interVar)}, 25);
}
然后,您可以运行inter()
并让它运行setInterval
答案 2 :(得分:0)
试试这个:
var ordersArray: [Int]!
let query = PFQuery(className: "Orders")
query.whereKey("customer", equalTo: customerLet)
query.findObjectsInBackgroundWithBlock({(objects, error) -> Void in
if objects!.count == 0{
self.ratingLabel.text = ("5.0")
}else{
if let objects = objects{
for object in objects{
let ordersAmount = objects!.count
self.ordersArray.append((Int(object.objectForKey("rating") as! String))!
let totalOrders = self.ordersArray.reduce(0, combine: +)
let ratingAverage = (totalOrders / ordersAmount)
}
}
}
})