Javascript String interpolate(replacements)

Description

Javascript String interpolate(replacements)


String.prototype.interpolate = function (replacements) {
    return this.replace(/\{(\w+)\}/g, function (match, capture) {
        if (replacements[capture]) {
            return replacements[capture];
        }/*from   www.  j  a v  a2  s.  co  m*/
        else {
            return match;
        }
    });
};



PreviousNext

Related