我没有在String.prototype中看到replaceAll,但是MDN已经提到了这个函数。当我使用它时,它会抛出一个TypeError:xxx.replaceAll is not a function?replaceAll是未来的ECMA标准吗?
1 回答

长风秋雁
TA贡献1757条经验 获得超7个赞
检查您的浏览器。这个方法很新,所以不建议使用它(如果当前浏览器不支持,或者实现替代)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll
就像是:
if (!String.prototype.replaceAll)
{
String.prototype.replaceAll = function(search, replace){
return this.split(search).join(replace);
}
}
添加回答
举报
0/150
提交
取消