var speed = 5;
var deltaTime = 0;
var lastTime = Date.now();
(function(){
deltaTime = (Date.now() - lastTime)/1000 ;
lastTime = Date.now();
ctx.fillStyle = "#000";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#59982f";
x -= speed * deltaTime;
ctx.fillRect(x, y, w, 20);
window.requestAnimationFrame(arguments.callee);
})()