String.prototype.myReplace = function (f, e) {//把f替换成e var reg = new RegExp(f, "g"); //创建正则RegExp对象 return this.replace(reg, e); }
let str = "2018-8-14";
let
str =
"2018-8-14"
;
str.myReplace(
'-'
,
'/'
)
//2018-8-14