There is var!

Please see:
        $scope.$watchCollection(rhs, function ngRepeatAction(collection){
          var index, length,
               ...
              arrayLength,

This is as it was before the change.
Please note that the goal was to refactor potentially long running piece of code into async one, but at the same time to leave it recognizable.