Virtual Life App with Inheritance

Feature Specification

 

 

Code Design

 

 

 

 

 

 

 

 

 

 

Notes

 

·         How to inherit from an object

 

ES5 methodology:

 

o    Invoke the parent object's constructor in the inherited object's constructor:

 
               function LivingWorldItem(...args) {
                       WorldItem.call(this, ...args);
               }
 

o    Set the inherited object's prototype to a copy of the parent's prototype:

 

   LivingWorldItem.prototype = Object.create(WorldItem.prototype);
 
 

ES6+ methodology:

 

o    Use the class keyword to create a new object class, and extend the parent class, passing along any constructor arguments to the superclass:

 
               class LivingWorldItem extends WorldItem {
                       constructor(...args) {
                               super(...args);
                       }
               }

References