字符串的format

在String的原型上增加该方法

String.prototype.format = function(){
        let args = arguments;
        return this.replace(/{(\d+)}/g,function(s,i){
            return args[i];
        })
    }

调用方式

"aa{0}".format('bb')     //aabb

猜你喜欢

转载自www.cnblogs.com/feiyangyao/p/12466427.html