Warning: String.x is deprecated; use String.prototype.x instead
关于字符串泛型的 JavaScript 警告出现在 Firefox 68 之前的版本。从 Firefox 68 开始,字符串泛型已经被移除,这些警告信息已经过时了。
信息
Warning: String.charAt is deprecated; use String.prototype.charAt instead Warning: String.charCodeAt is deprecated; use String.prototype.charCodeAt instead Warning: String.concat is deprecated; use String.prototype.concat instead Warning: String.contains is deprecated; use String.prototype.contains instead Warning: String.endsWith is deprecated; use String.prototype.endsWith instead Warning: String.includes is deprecated; use String.prototype.includes instead Warning: String.indexOf is deprecated; use String.prototype.indexOf instead Warning: String.lastIndexOf is deprecated; use String.prototype.lastIndexOf instead Warning: String.localeCompare is deprecated; use String.prototype.localeCompare instead Warning: String.match is deprecated; use String.prototype.match instead Warning: String.normalize is deprecated; use String.prototype.normalize instead Warning: String.replace is deprecated; use String.prototype.replace instead Warning: String.search is deprecated; use String.prototype.search instead Warning: String.slice is deprecated; use String.prototype.slice instead Warning: String.split is deprecated; use String.prototype.split instead Warning: String.startsWith is deprecated; use String.prototype.startsWith instead Warning: String.substr is deprecated; use String.prototype.substr instead Warning: String.substring is deprecated; use String.prototype.substring instead Warning: String.toLocaleLowerCase is deprecated; use String.prototype.toLocaleLowerCase instead Warning: String.toLocaleUpperCase is deprecated; use String.prototype.toLocaleUpperCase instead Warning: String.toLowerCase is deprecated; use String.prototype.toLowerCase instead Warning: String.toUpperCase is deprecated; use String.prototype.toUpperCase instead Warning: String.trim is deprecated; use String.prototype.trim instead Warning: String.trimLeft is deprecated; use String.prototype.trimLeft instead Warning: String.trimRight is deprecated; use String.prototype.trimRight instead
错误类型
警告。JavaScript 的执行不会停止。
哪里出错了?
非标准的泛型 String
方法已经被废弃,已经在 Firefox 68 及更新版本中移除。String 泛型在 String
对象上提供了一系列的 String
实例方法,使得这些方法可以应用于任何类型的对象。
示例
废弃的语法
const num = 15;
String.replace(num, /5/, '2');
标准语法
const num = 15;
String(num).replace(/5/, '2');