function Fn(str){ this.str = str; } Fn.prototype.format = function(){ var arg = arguments; var dd = this.str.replace(/{[0-9]}/g,function(a,b){ var _index = a.replace(/{|}/g,''); console.log(_index); return arg[_index]||'' }) return dd; } var fn = new Fn('<p><a href="{0}">{1}</a></p>') document.write (fn.format('http://www.baidu.com/','百度'));