js字符串格式化方法format

/**
 * 设置字符串format函数
 * 例子: '{0}{1}.format(5,6)'
 */
setStringFormat() {
  String.prototype['format'] = function () {
    const e = arguments;
    return !!this && this.replace(/\{(\d+)\}/g, function (t, r) {
      return e[r] ? e[r] : t;
    });
  };
}

猜你喜欢

转载自blog.csdn.net/ligaoming_123/article/details/83030671
今日推荐