Fixed a jsHint warning reg function inside a loop