javascript字符串格式化string.format

String.prototype.format = function () {
    var values = arguments;
    return this.replace(/\{(\d+)\}/g, function (match, index) {
        if (values.length > index) {
            return values[index];
        } else {
            return "";
        }
    });
};  

使用:

 

posted @ 2018-01-26 13:06  绿皮儿橘子  阅读(9557)  评论(0编辑  收藏  举报