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/','百度'));
面试时遇到的题目。正则,replace()
猜你喜欢
转载自www.cnblogs.com/aiyr/p/10697898.html
今日推荐
周排行