I would recommend the following changes:
define the variable in rebuildMasks() using let
function rebuildMasks() {
let maskFields = _getMaskFields();
let masks = _getMasks(maskFields);
_setupMaskEvents(maskFields, masks);
}
remove the current initialization code and put the following at the bottom of the script:
// Initialize when document is loaded
document.addEventListener("DOMContentLoaded", rebuildMasks);
There is no reason for maskFields and masks to be global variables, and the initialization code was just a duplicate of the rebuildMasks() function, and initializing the masks should not happen before the entire document is loaded.
If you want, I can fork and make those changes and put it into a pull request...
I would recommend the following changes:
define the variable in rebuildMasks() using let
remove the current initialization code and put the following at the bottom of the script:
There is no reason for maskFields and masks to be global variables, and the initialization code was just a duplicate of the rebuildMasks() function, and initializing the masks should not happen before the entire document is loaded.
If you want, I can fork and make those changes and put it into a pull request...