String和Array泛型方法将来会被弃用 [英] String and Array generics methods will be deprecated in the future

查看:70
本文介绍了String和Array泛型方法将来会被弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的链接(MDN网站)上,它说字符串泛型是非标准的,已弃用,将来可能会被删除。请注意,如果不使用下面提供的填充程序,则不能跨浏览器依赖它们。

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."

他们所指的方法是指他们在本声明下面提供的垫片中列出的方法吗?这是对我所看到的短语String generics的唯一引用,因此令我感到困惑。

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.

对于Array泛型也是同样的问题,因为该网站提到了类似的情况他们也是。

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 / zh-CN / docs / Web / JavaScript / Reference / Global_Objects / Array#Array_generic_methods

推荐答案

Generic 表示引用所有,在这种情况下,它表示独立于实例的方法,即

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.

如果您使用这种方式访问​​ bar 类型 Foo 的方法,可以在 Foo-like 上使用它们,通过 Foo.prototype.bar.call 代替,即

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

这篇关于String和Array泛型方法将来会被弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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