Classes vs Prototypes, what's the difference?

Hi all!

So I’m about 8 weeks into studying Javascript, and I am currently reading Javascript, The Definitive Guide which honestly is an exhaustive documentation of everything Javascript has to offer, which is great but I’m having trouble retaining it all.

I recently got to the Chapter on Javascript classes (Chapter 9) and am struggling to understand the differences between Prototypes and Classes. I am somewhat grasping the concept, but I thought some of the crew here at FCC might be able to help me understand the differences more succinctly.

So far I have only come across references to Prototypes and Prototype based inheritance, so this somewhat similar concept of Classes is eluding me at the moment, and any clarification on the topic of Classes and its uses when it comes to programming would be greatly appreciated.

Thanks in advance, the crew here has been extremely helpful thus far in my slow but steady journey towards learning Javascript.

1 Like

A prototype is an object that is the property of an object. The prototype property holds all the methods, and other properties you want to be inherited including the constructor itself. If you were to create an instance of a class such as foo = new Foo() you could see that foo inherited the constructor of Foo by doing foo.__proto__ or the more proper way which is Object.getPrototypeOf(foo). Anytime you use a method on an object, or array you are traversing its prototype chain until you get to where it inherits the property and in most cases this will be the global Object or Array. To put it simply a class has a prototype that is a kind of blueprint.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.