Edit in JSFiddle

var ctx = canvas.getContext('2d'),
    W,H,
    mem = {},
    t = 0;
canvas.width = W = innerWidth;
canvas.height = H = innerHeight;
function add(o){
  o.id = ++t;
  mem[o.id] = o;
};
function remove(o){
  delete mem[o.id];
};
function Square(){
  var w = 2,
      h = 2,
      x = 0-w,
      y = Math.floor(Math.random()*H),
      v = Math.random()*(W/32)+1;
  this.run = function(){
    x += v;
    if(x > W){
      remove(this);
      new Square();
    }
    ctx.save();
    ctx.fillStyle = '#fff';
    ctx.fillRect(x,y,w,h);
    ctx.restore();
  }
  add(this);
};
(function loop(){
  new Square();
  setTimeout(loop,1000/12);
})();
(function loop(){
  ctx.fillRect(0,0,W,H);
  for(var a in mem){
    mem[a].run();
  }
  if(t > 3000){
    t = 0;
  }
  setTimeout(loop,1000/60);
})();
*{
  margin:0;
  padding:0;
}
canvas{
  border:1px solid #ccc;
}
<canvas id="canvas"></canvas>