Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String and Array generics methods will be deprecated in the future

At the link below (MDN site) it says "String generics are non-standard, deprecated and might get removed in the future. Note that you can not rely on them cross-browser without using the shim that is provided below."

Are the methods they are referring to the methods listed in the shim they provide below this statement? This is the only reference to the phrase "String generics" I have seen so it's confusing me.

Also the same question for Array generics as the site mentions a similar situation for them as well.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_generic_methods

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Array_generic_methods

like image 225
gr4vy Avatar asked Aug 23 '15 23:08

gr4vy


1 Answers

Generic means "referring to all", and in this case it means the methods which are independent from the instances, i.e.

var foo = 'bar';
String.split(bar, 'a'); // "generic" method, non-standard, will throw ReferenceErrors
bar.split('a'); // instance method, standard

It is very unlikely you've written any code in the non-standard way as it already won't work on most people's browsers.


If you were using this way of accessing bar a method for type Foo to use them on Foo-like things, go via Foo.prototype.bar.call instead, i.e.

var baz = {length: 2, 0: 'fizz', 1: 'buzz'}; // Array-like
Array.slice(baz, 0, 1); // bad
Array.prototype.slice.call(baz, 0, 1); // good
like image 53
Paul S. Avatar answered Nov 04 '22 02:11

Paul S.