String.format = function()
{
if( arguments.length == 0 )
{
return null;
}
var str = arguments[0];
for(var i=1;i
{
var re = new RegExp('\\{' + (i-1) + '\\}','gm');
str = str.replace(re, arguments[i]);
}
return str;
}
使用方式 : String.format('Hello. My name is {0} {1}.', firstName, lastName);