SiteMap  | About    

Classical Vs. Prototypal inheritance

Classic Inheritance

A class is like a blueprint . The classical approach to creating an object is to define the structure of the object, using a CLASS declaration , and instantiate that class to create a new object. Objects created in this manner have their own copies of all instance attributes, plus a link to the single copy of each of the instance methods. Inheritance is the tightest coupling available in OO design. Also, descendant classes have an intimate knowledge of their ancestor classes.

Prototypical Inheritance

JavaScript does not have classes unlike other languages. It uses the concept of prototypes and prototype chaining for inheritance. Prototypal inheritance is all about objects. Objects inherit properties from other objects. In prototypal inheritance, instead of defining the structure through a class, you simply create an object. This object then gets reused by new objects . Instances are typically instantiated via factory functions or Object.create() method. Instances may be composed from many different objects, allowing for easy selective inheritance. It is more flexible than Classic Inheritance . Any existing object can become a class from which additional objects will be spawned. This is handy where your objects offer several sets of services and/or they undergo a lot of state transformation before your program arrives at the point where the inheritance is needed. (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.