JavaScript Engine Rules

Leadows Technologies
3 min readMar 11, 2021

1. Every object must be created from a class

2. Every object has a property __proto__

3. __proto__ of an object always refers to prototype object of the class from which the object was created

4. Every class is a function object, and hence it is created from Function class

5. As every class is a Function object, its __proto__ always refers to prototype object of Function class

6. Function class is also a Function object

7. Every class inherits Object class

8. prototype object is used for inheritance

CODE:

let assert = require("assert");// Every class has a prototype property, because every class is a function object// function object is created from the Function class
let f1 = function () { };
assert.equal(typeof f1, "function");
// function object contains prototype property
assert.notEqual(f1.prototype, undefined);
// function object is created from the Function class
assert.equal(f1.__proto__, Function.prototype);
// Function class inherits Object class
assert.equal(Function.prototype.__proto__, Object.prototype);
// every function object is created from the Function class
assert.equal(Function.__proto__, Function.prototype);
// 10 is created from the Number class
let f2 = 10;
assert.equal(typeof f2, "number");// number object does not contain prototype property
assert.equal(f2.prototype, undefined);
// number object is created from the Number class
assert.equal(f2.__proto__, Number.prototype);
// Number class inherits Object class
assert.equal(Number.prototype.__proto__, Object.prototype);
// Number class/function object is created from the Function class
assert.equal(Number.__proto__, Function.prototype);
// hello is created from the String class
let f3 = "hello";
assert.equal(typeof f3, "string");
// string object does not contain prototype property
assert.equal(f3.prototype, undefined);
// string object is created from the String class
assert.equal(f3.__proto__, String.prototype);
// String inherits Object class
assert.equal(String.prototype.__proto__, Object.prototype);
// String class/function object is created from the Function class
assert.equal(String.__proto__, Function.prototype);
let f4 = true; // true is created from the Boolean class
assert.equal(typeof f4, "boolean");
// boolean object does not contain prototype property
assert.equal(f4.prototype, undefined);
// boolean object is created from the Boolean class
assert.equal(f4.__proto__, Boolean.prototype);
// Boolean class inherits Object class
assert.equal(Boolean.prototype.__proto__, Object.prototype);
// Boolean class/function object is created from the Function class
assert.equal(Boolean.__proto__, Function.prototype);
let f5 = {}; // {} is created from the Object class
assert.equal(typeof f5, "object");
// { } does not have prototype property
assert.equal(f5.prototype, undefined);
// { } is created from the String class
assert.equal(f5.__proto__, Object.prototype);
// Object class/function object is created from the Function class
assert.equal(Object.__proto__, Function.prototype);
let f6 = []; // [] is created from the Array class
assert.equal(typeof f6, "object");
// [ ] does not have prototype property
assert.equal(f6.prototype, undefined);
// [ ] is created from the Array class
assert.equal(f6.__proto__, Array.prototype);
// Array inherits Object class
assert.equal(Array.prototype.__proto__, Object.prototype);
// Array class/function object is created from the Function class
assert.equal(Array.__proto__, Function.prototype);
  • Run it in Node platform

--

--

Leadows Technologies

A software development company, with a bunch of passionate coders. Get your software developed with us, and experience robustness, reliability, low maintenance.