if (typeof ''.replaceAll != 'function') {
console.log('[不兼容]replaceAll')
String.prototype.replaceAll = function (oldStr, newStr) {
return this.replace(new RegExp(oldStr, 'g'), newStr);
}
}
console.log('[不兼容]replaceAll'.replaceAll('不兼容', '兼容处理'));
使用typeof ''.replaceAll != 'fnction'
判断是否replaceAll是否为方法如不是方法的话,通过String
原形链增加replaceAll
方法处理。
添加的最先加载执行的地方。