function result(tpl,data){
var pattern = /{\\w+}/g;
var matches = pattern.exec(tpl);
var desc =tpl.replace(pattern,"%s");
console.log(desc,data.name,data.age,data.city);
}
var data1={name:'abc',city:'cheng',age:"dd"}
var desc = "我是{name},今年{age},来自{city}"
result(desc,data1);
网友评论