Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Help!!! this is complicated

what is an instance in javascript and what is array.prototype, shift .prototype, I still didn't understand what is the all prototype thing in javascript.

1 Answer

Dario Bahena
Dario Bahena
10,697 Points

Imagine an apple. If you imagined a red one, someone else might have imagined a green one. When you pick an apple from a tree whatever color it may be, that is an instance of an apple. the prototype is a property that all instances of objects have that is shared among them. The prototype can be modified on the object itself and will affect all of the instances of that object but only in that special prototype property.

Array.prototype // this contains a bunch of methods including map, pop, push

const foo = [1,2,3,4]

foo.prototype // this will contain the same methods as Array.prototype

Array.prototype.test = 'whatever' // the test property is now available to all arrays

foo.test // this now works because it is part of the prototype and will be there in any array you create

Side note, this just illustrates a point. It is bad practice to mutate built in prototypes.