I have the following that is iterating over an array of “templateOverrides”. DPGlobal.template is the original template which I need to override. My issue is that I need to pass the g flag to the .replace() method on the var newTemplate = ... line. It’s working insofar as I am able to dynamically iterate through and override template pieces one at a time, but the g flag is not passed. I’m mainly curious what is the most DRY method of achieving it…
for ( var i in templateOverrides ) {
var thisOverride = templateOverrides[i];
var origGlobalTemplate = DPGlobal[thisOverride];
var newTemplate = DPGlobal.template.replace(origGlobalTemplate, options[thisOverride]);
DPGlobal.template = newTemplate;
i++;
}
If you declare it via
new RegExp(), you can then include the/gmodifier as the second parameter to the constructorBy the way, is
templateOverridesreally anArray [], or is it an object{}? If it is anArray, you ought to be using an incremental for loop rather thefor-inconstruct, whose purpose is iterating over object properties.