快速组装字符串,类似c#里面的string.format function format(template) { var args = Array.prototype.slice.call(arguments, 1); if (args.length = 0) return template; return template.replace(/\{(\d+?)\}/g, function($0, $1) { var val
function format(template) {
var args = Array.prototype.slice.call(arguments, 1);
if (args.length <= 0) return template;
return template.replace(/\{(\d+?)\}/g, function($0, $1) {
var val = args[parseInt($1)];
if (val === undefined) return "";
return val;
});
}
使用说明
format('{0}-{1}', 'anlige', 23);
