String和Array泛型方法将来会被弃用

编程入门 行业动态 更新时间:2024-10-27 08:39:44
本文介绍了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.

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

developer.mozilla / 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泛型方法将来会被弃用

本文发布于:2023-11-25 18:31:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将来   方法   String   Array   会被弃用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!