JSFiddle - React, Tailwind, and code Playground

by greenlaw110

JavaScript

function BaseStoreClass(name) {
    var self = this;
    this.name = name;
    this.store = {
        state: function() {
            return self.getState();
        }
    };
}
BaseStoreClass.prototype.getState = function() {
    return {
        name: this.name
    }
};
BaseStoreClass.prototype.sayHi = function() {
    alert('hi ' + this.name);
}
function MyStoreClass(name, age) {
    BaseStoreClass.call(this, name);
    this.age = age;
}
MyStoreClass.prototype = new BaseStoreClass();
MyStoreClass.constructor = MyStoreClass;
MyStoreClass.prototype.parent = BaseStoreClass.prototype;
MyStoreClass.prototype.getState = function() {
    var state = this.parent.getState.call(this);
    state['age'] = this.age;
    return state;
};
var store0 = new BaseStoreClass('bar');
var store = new MyStoreClass("foo", 100);
console.log({s0: store0.getState(), s1: store.getState()});
store0.sayHi();
store.sayHi();