
作为一个还在没使用ES6字符串模版的程序员。最讨厌的就是拼接字符串了,一堆「+」在代码中,根本影响阅读是不是?有时候还容易漏空格对不对?今天就来优雅的解决一下这个问题。

就是用str.replace(regexp|substr, newSubstr|function)
~


例子举的很简单,但是replace
还能接受函数啊是不是,你想怎么枚举都方便了。所以使用replace
代码阅读体验一下子就提高了不少。
以上。
作为一个还在没使用ES6字符串模版的程序员。最讨厌的就是拼接字符串了,一堆「+」在代码中,根本影响阅读是不是?有时候还容易漏空格对不对?今天就来优雅的解决一下这个问题。
就是用str.replace(regexp|substr, newSubstr|function)
~
例子举的很简单,但是replace
还能接受函数啊是不是,你想怎么枚举都方便了。所以使用replace
代码阅读体验一下子就提高了不少。
以上。
本文标题:#每日一记#让我们优雅的拼接字符串
本文链接:https://www.haomeiwen.com/subject/jvqvattx.html
网友评论