Prototypes

When a new Object is formed, the JS engine adds a proto property to the new object. This points to the prototype object of the constructor function. All JS objects take in, or inherit, properties and methods from a prototype. For instance, Dog objects inherit from Dog.prototype. String objects inherit from String.prototype.

The JS prototype property lets you add new properties to object constructors. For example, using ES2015 notation:

Image for post

Ernie was my childhood dog — this post goes out to you, buddy!

The above prints “Ernie Bade is my name. I am 6 years old and my breed is Golden Retriever,” because we have added a property of about to the Dog prototype.

Classes

#javascript #iife #closures-functions #class #prototype

JS Interview Help: Prototype, Class(ES6), IIFE, Scope, Closures, Module Pattern
1.30 GEEK