首页 > 其他 > 详细

面试时遇到的题目。正则,replace()

时间:2019-04-12 19:33:46      阅读:165      评论:0      收藏:0      [点我收藏+]
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()

原文:https://www.cnblogs.com/aiyr/p/10697898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!