在下面的链接(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泛型方法将来会被弃用
发布评论