JSFiddle - React, Tailwind, and code Playground

by s1owjke

HTML

<b>Sandbox</b> Play with Object Prototypes

JavaScript

function class0 () {
	this.prop = 'class0';
}

function hello () {
	alert(1);
}

// static will be defined as class0.hello

class0.prototype.hello = function () {
	console.log(this, class0, this.__proto__ == class0.prototype, class0.__proto__, class0.prototype);
};

class0.helloStatic = function () {

}

class class1 extends class0 {
	constructor() {
    	super();
    	this.prop = 'class1';
    }
    hello() {
    	console.log(this, class1, this.__proto__ == class1.prototype, class1.prototype);
    }
}

// named can use internal2 inside
let class2 = class internal2 {
	constructor() {
    	this.prop = 'class2';
    }
    hello() {
    	// class2 and internal2 are same
    	console.log(this, class2, internal2, this.__proto__ == class2.prototype, class2.prototype);
    }
}

let class3 = class {
	constructor() {
    	this.prop = 'class3';
    }
    hello() {
    	console.log(this, class3, this.__proto__ == class3.prototype, class1.prototype);
    }
}

let instance0 = new class0;
instance0.hello();

let instance1 = new class1;
instance1.hello();

let helloInstance = new hello;
console.log(helloInstance);

/* let instance2 = new class2;
instance2.hello();

let instance3 = new class3;
instance3.hello(); */

//Упаковка в прототипных и статических методах