JSFiddle - React, Tailwind, and code Playground

by petroveg

JavaScript

function Class (name) {
	this.name = name;
}

Class.prototype = {
	set a (n) {
		this.value = 'Owner: ' + n;
	},
	get b () {
		return this.value;
	}
};

function SomeClass () {
	Class.call(this);
}

function OtherClass () {
	Class.call(this);
}

OtherClass.prototype = Object.create(Class.prototype, {
	a: {
		set: function (n) {
			this.value = 'Other: ' + n;
		}
	}
});

SomeClass.prototype = Object.create(Class.prototype);
Object.defineProperty(SomeClass.prototype, 'a', {
	set: function (n) {
		this.value = 'Some: ' + n;
	}
});

var x = new Class('One'),
	y = new OtherClass('Two'),
	z = new SomeClass('Three');

x.a = 3;
console.log(x.b);

y.a = 5;
console.log(y.b);

z.a = 7;
console.log(z.b);