JSFiddle - React, Tailwind, and code Playground
JavaScript
var Person = CLASS({
constructor: function () {
this.name = "my name";
},
sayHello: function () {
alert("Hello, I am a person.");
},
sayGoodbye: function () {
alert("Goodbye");
}
});
var Student = CLASS({
constructor: function () {
this.studentId = 0;
},
sayHello: function () {
alert("Hello, I am a student.");
}
}, Person);
var student = new Student;
student.sayHello();
student.sayGoodbye();
function CLASS(prototype, base) {
switch (typeof base) {
case "function": base = base.prototype;
case "object": prototype = Object.create(base, descriptorOf(prototype));
}
var constructor = prototype.constructor;
constructor.prototype = prototype;
return constructor;
}
function descriptorOf(object) {
return Object.keys(object).reduce(function (descriptor, key) {
descriptor[key] = Object.getOwnPropertyDescriptor(object, key);
return descriptor;
}, {});
}