0

I was reading the documentation on the slice function and saw that the title of the page was: "Array.prototype.slice()".

Why is the keyword prototype between Array and slice()?

Here is the page: documentation

Any references to official documentation would be very helpful!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Robert
  • 10,126
  • 19
  • 78
  • 130
  • 3
    http://stackoverflow.com/questions/572897/how-does-javascript-prototype-work?rq=1 – Phil-R Aug 18 '14 at 21:46
  • The reason `.slice()` is available from every array instance is that it's a property of the Array prototype. – Pointy Aug 18 '14 at 21:48
  • This answer contains a lot of details about constructor functions and the role of prototype: http://stackoverflow.com/questions/16063394/prototypical-inheritance-writing-up/16063711#16063711 – HMR Aug 19 '14 at 02:58

1 Answers1

1

This is the way JvaScript handles inheritance. It's a topic of depth, so this isn't a full answer, but essentially the Array.prototype.slice is saying "Slice is now a method available to objects of the class Array"

Read about prototypal inheritance to get a better idea: http://www.laktek.com/2011/02/02/understanding-prototypical-inheritance-in-javascript/

Brennan
  • 5,632
  • 2
  • 17
  • 24
  • Thanks this really made a lot of since and why the word 'prototype' is specifically used! – Robert Aug 18 '14 at 22:05
  • The article you link to creates an instance of parent to set up prototype part of inheritance (bad) and then doesn't re use parent constructor by doing something like Parent.call(this) (very bad). The child now has parent instance specific members on it's prototype (hared) – HMR Aug 19 '14 at 03:03