11

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

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

enter image description here


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

2
  • @Kris no, it's not a duplicate. Firefox really does have additional methods that are not part of the prototype. Commented Dec 7, 2017 at 9:06
  • Ok sorry you are right, got trapped the same way like all the upvoters from the second answer... Commented Dec 7, 2017 at 9:15

1 Answer 1

4

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)

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.

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

Sign up to request clarification or add additional context in comments.

7 Comments

My firefox also shows Array.isArray with Object.getOwnPropertyName(Array) however does not show with just console.log(Array) How about you?
@soonoo Likewise, it doesn't appear in the console.log output, but it does appear in the object inspector pane. Perhaps it's a bug in the console?
Thanks but still confused ㅠㅠ
@soonoo what's the confusion?
it's not your answer, just about firefox's non-general behavior
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.