Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Joel Pendleton
Joel Pendleton
19,230 Points

What is prototype in layman's terms?

Can anyone explain the purpose, use and definition of prototype, in simple layman's terms, to me?

3 Answers

The way I understand prototypes:

Javascript is a "classless" object-oriented language, whereas some OO languages such as Java use classes. A class is a static (compile-time) representation of how an object will be eventually realized. Classes are used to describe how an object will inherit properties from other classes.

Now Javascript does not have the class mechanism; objects are just created directly at run-time. In order to give additional properties (and methods) to a new object, you just construct it using the template of an existing parent and then "glue on" additional properties to provide specialization. This scheme is called "prototypal inheritance" and gives Javascript a powerful way to specialize objects as needed. One path of execution may create a specialized property on an object, whereas another path may not.

One secret superpower of prototypal inheritance is to "cache" common methods (functions) between objects efficiently. Instead of having to specify the same function in each object that will use it, you can create a pointer to a function and share it among objects that want to use it. The common function can be maintained in one spot (DRY).

I hope this helps, take care!

-- Calvin

Joel Pendleton
Joel Pendleton
19,230 Points

Does realized mean displayed?

Brian Steele
Brian Steele
23,060 Points

Try this. There are a lot of helpful articles on the site.

Hi Joel,

A better way to say "realizing an object" is for me to use the proper term: "instantiating an object".

An object is instantiated when it becomes active at run-time. Its properties keep track of state (can be written to and will remember changes), and its methods are accessible (can be called and will return values).

Take care..!

-- Cal