JS - 给String.prototype添加replaceAll方法

String.prototype.replaceAll = function (targetStr, newStr) {
  var sourceStr = this.valueOf();
  while (sourceStr.indexOf(targetStr) !== -1) {
    sourceStr = sourceStr.replace(targetStr, newStr);
  }
  return sourceStr;
};

posted @ 2018-05-08 15:59  AndreMao  阅读(1205)  评论(4编辑  收藏  举报