Non-standard String generics have been deprecated

Published: | Categories: JavaScript

Description

The non-standard, Firefox-specific String generic methods, introduced with JavaScript 1.6, are now considered deprecated and will be removed in the near future. These generic/static methods include:

  • String.charAt
  • String.charCodeAt
  • String.concat
  • String.endsWith
  • String.includes
  • String.indexOf
  • String.lastIndexOf
  • String.localeCompare
  • String.match
  • String.normalize
  • String.replace
  • String.search
  • String.slice
  • String.split
  • String.startsWith
  • String.substr
  • String.substring
  • String.toLocaleLowerCase
  • String.toLocaleUpperCase
  • String.toLowerCase
  • String.toUpperCase
  • String.trim
  • String.trimLeft
  • String.trimRight

Here are some alternatives to the generics:

// Deprecated
String.replace(num, search, replace);
// Alternative 1: the String global object
String(num).replace(search, replace);
// Alternative 2: the old-school way
String.prototype.replace.call(num, search, replace);

Note that the standard instance methods on String.prototype won’t be affected, of course. The following static methods are also in the ECMAScript 2015 (ES6) spec and therefore they won’t be removed:

Update: String generics have been removed with Firefox 68.

Update 2 The earlier version of this note mentioned Array generics as well, but Array generics have been officially deprecated since Firefox 68, not Firefox 53. We have corrected the note.

References