简体   繁体   English

浏览抛出错误replaceAll不是函数

[英]browsing throwing error replaceAll is not a function

I'm getting this error on chrome 84 somehow still not sure if it's the replaceAll method that is the problem or the function我在chrome 84上遇到此错误,但仍不确定问题是 replaceAll 方法还是函数

Intl.DateTimeFormat(...) .resolvedOptions(...) .timeZone.replaceAll is not a function Intl.DateTimeFormat(...) .resolvedOptions(...) .timeZone.replaceAll不是函数

function GetHumanTimezone() {
  return Intl.DateTimeFormat().resolvedOptions().timeZone.replaceAll('_', '-');
}

Replaceall is useless in my opinion. Replaceall 在我看来是没用的。 Just do .timeZone.replace(/_/g, '-');只需执行.timeZone.replace(/_/g, '-');

but if you insist:但如果你坚持:

For your ancient Chrome you can do对于您的古老 Chrome,您可以这样做

 if (!"".replaceAll) String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; console.log(Intl.DateTimeFormat().resolvedOptions().timeZone.replaceAll("_", "-"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM