Array.function和Array.prototype.function有什么区别? [英] What is the difference between Array.function and Array.prototype.function?

查看:128
本文介绍了Array.function和Array.prototype.function有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现某些功能如 concat() push() 每个()都存在于 Array Array.prototype (使用firefox 57.0.1控制台) )

I've found that some functions like concat() push() every() both exist in Array and Array.prototype(with firefox 57.0.1 console)

由于原型方法存在于数组中,这令人困惑。

此外,staic在哪里方法( Array.from() Array.isArray() etc)存在于?

It's confusing since prototype methods exist in Array.
Additionally, where does staic method(Array.from(), Array.isArray() etc) exists in?

我想我我在某种程度上理解了javascript原型的概念,所以我很好奇为什么原型方法( concat() push() ...)apear在数组 Array.prototype

I think I've understood concepts of javascript prototype to some extent, so what I'm curious about is why prototype methods(concat() push() ...) apear both in Array and Array.prototype

推荐答案

Firefox的数组函数似乎有额外的(不符合的)静态方法复制原型方法的ods除了它们将数组作为第一个参数而不是通过隐式这个上下文。

Firefox's Array function appears to have additional (non-conformant) "static" methods that replicate the prototype methods except that they take the array as the first parameter instead of via the implicit this context.

要查看数组的方法和属性,请使用:

To see those methods and properties of Array, use:

Object.getOwnPropertyNames(Array)

在Firefox中,您(大多数)会看到与您的列表相同的列表第一个截图。我还没弄清楚为什么列表中缺少 Array.isArray ,但它确实出现在我的Firefox 57中。

In Firefox you'll (mostly) see the same list as in your first screenshot. I haven't yet figured out why Array.isArray is missing in your list, but it does appear in my Firefox 57.

在Chrome中,您只会看到ES6强制要求的静态方法(即 Array.from Array.isArray Array.of )和标准属性。

In Chrome you'll only see the ES6 mandated "static" methods (i.e. Array.from, Array.isArray, Array.of) and the standard properties.

这篇关于Array.function和Array.prototype.function有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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