Javascript String interpolate(opts)

Description

Javascript String interpolate(opts)


String.prototype.interpolate = function (opts) {
    var reg = /\$\{(.*?)\}/g,
        str = this,/* www.ja  v  a  2  s.  co m*/
        res;

    while (res = reg.exec(str)) {
        str = str.replace(res[0], opts[res[1]]);
    }
    return str;
};



PreviousNext

Related