JS replace the placeholder

String.prototype.format = function() {
        if(arguments.length === 0) return this;
        var obj = arguments[0];
        var s = this;
        for(var key in obj) {
            s = s.replace(new RegExp("\\{\\{" + key + "\\}\\}", "g"), obj[key]);
        }
        return s;
    }; 

  

Guess you like

Origin www.cnblogs.com/hnhycnlc888/p/10966727.html
Recommended