替换事件的Javascript全局函数

时间:2020-05-01 13:55:41

标签: javascript node.js typescript

是否有一些更清洁的方法来执行此操作,而不是多次调用该函数 谢谢 。 因为我想将该功能用于评论,注释和描述

replaceOccurrences(originalString) {
    let newString;
    // eslint-disable-next-line camelcase
    const html_entity = '#';

    // eslint-disable-next-line no-mixed-operators
    if (originalString && originalString.includes('#')) {
      // eslint-disable-next-line no-shadow
      const newString = originalString.replace(/#/g, html_entity);
      return newString;
    }
    return originalString;
  }


 let description = this.getDescription(submission.request);
            description = this.replaceOccurrences(description);

            const comment = this.replaceOccurrences(a.comment);

            let notes = this.getNotes(a, question, submissions);
            notes = this.replaceOccurrences(notes);

0 个答案:

没有答案