I'm trying to wrap a setTimeout in an immediately invoked function expression which creates the function, which then calls itself again as above, and automatically starts the loop:
Here is the reference: enter link description here
For some reason it runs once and then stopped.
//Spaceship move
function spaceShipMove(spaceShipToMove){
var randomY = Math.floor(Math.random());
spaceShipToMove.style.webkitTransform = 'translate(-3000px, ' + randomY + 'px)';
}
//Spaceship
var spaceShipsList = createMultipleSpaceShips(500);
for (var i = 0; i < spaceShipsList.length; i++){
var aSpaceShip = spaceShipsList[i];
app.dom.mainWrapper.appendChild(aSpaceShip);
(function t() {
setTimeout(function (spaceShipGo) {
spaceShipMove(spaceShipGo);
}, i * 300, aSpaceShip)
})();