const subrefs = []; let i = 0; for ( let j = 3; j--; ) { i++; subrefs.push( function(){ console.log( i ); } ); } for ( const subref of subrefs ) { subref(); }