Javascript .replaceAll() 不是函数类型错误 [英] Javascript .replaceAll() is not a function type error

查看:53
本文介绍了Javascript .replaceAll() 不是函数类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档页面:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

let string = ":insertx: :insertx: :inserty: :inserty: :insertz: :insertz:";
let newstring = string.replaceAll(":insertx:", 'hello!');

当我运行它时,我收到Uncaught TypeError: string.replaceAll is not a function.也许我误解了什么是原型,但该函数似乎是一个可用的字符串方法.

When I run this, I receive Uncaught TypeError: string.replaceAll is not a function. Maybe I'm misunderstanding what a prototype is, but the function appears to be a string method that is available for use.

我使用的是 Chrome.

I'm using Chrome.

推荐答案

.replaceAll 将在 Chrome 85 上可用.当前版本为 83.

.replaceAll will be available starting on Chrome 85. The current version is 83.

如果您下载 Google Chrome Canary(版本 86),您将能够看到您的代码运行良好.Firefox 的版本为 78,并且由于 .replaceAll 从版本 77 开始可用,因此它也可以在该版本中使用.它也适用于当前的 Safari.Microsoft Edge 认为它不受支持.

If you download Google Chrome Canary (which is on version 86), you'll be able to see that your code runs fine. Firefox is on version 78, and since .replaceAll has been available starting version 77, it works there too. It will work on current Safari as well. Microsoft Edge has it as unsupported.

您会在问题中的文章底部找到支持的浏览器版本.

You'll find supported browser versions at the bottom of the article in your question.

这篇关于Javascript .replaceAll() 不是函数类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆