String.prototype.format=function(){
var content = this;
for(var i = 0; i < arguments.length; i++){
var reg = new RegExp("\\{" + i + "\\}", "g");
content = content.replace(reg, arguments[i]);
}
return content;
}
var s="my name is {0}, I'm {1} years old, and I have {2} brother.";
s=s.format("wendy",24,2);
console.log(s);
prototype:用来添加字符串属性和方法
arguments: 所有函数的局部变量,不是Array,只有length、index
RegExp:’g’(全局匹配)、’i’(区分大小写匹配)、’m’(多行匹配)