javascript 仿 C# format

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

}

"hello {0},{0}'s age is {1}".format("tom",12)

 

posted @ 2016-04-15 11:56  大赚佬  阅读(129)  评论(0编辑  收藏  举报