Javascript - Prototype Chain - Hierarchy (Sort of Inheritance)

About

inheritance doesn't exist in Javascript but an object can be created from a prototype (Composition or linked list ?)

You can then see what was the prototype of the prototype.

Prototype Hierarchy

Function

A function that prints the prototype of the prototype of the ..

var element = document.querySelector("body");
while (element.__proto__ != null) {
    
    // Print the prototype
    console.log(element.__proto__.toString());
    
    // Element becomes the prototype of the prototype
    element = element.__proto__;
    
}

The body element comes from the following chain of prototype.

Devtool

You can also see the chain of prototype in the dev tool. For instance for Chrome:

Prototype Chain Dev Tool Chrome





Discover More
Javascript - (Prototype Model|Prototypical object)

A prototype-based language has the notion of a prototypical object. Any object can: specify its own properties, either when you create it or at run time. be associated as the prototype for another...
Javascript Lexical Environment Scope Chaine
Javascript - (Variable) Scope (Namespace)

Variable scope in Javascript. variable scope is delimited by the function definition, not a the block level A block has the scope of its inner function. As a function is also an object, by generalization,...
Javascript - Object

object in javascript An object is a data type in Javascript. An object follows a json data structure with key that holds property value. The value may be of a variable or a function In JavaScript, a...
Javascript - instanceof

instanceof instanceofObjectprototype An object created from a class will always be as an instanceof its class. The constructor of a function createdWITHOUT a prototype will beNOT recognized...



Share this page:
Follow us:
Task Runner