JSFiddle - React, Tailwind, and code Playground

by Alexander

JavaScript

"use strict";

console.clear();

$.Class = function(){};
$.Class.extend = function(prop){
    var _super = this.prototype;
    var initializing = true;

    var prototype = $.extend({}, _super, prop);

    initializing = false;

    function Class(){
        if (initializing) return;
        if (this.init)
            this.init.apply(this, arguments);
    }

    Class.prototype = prototype;
    Class.constructor = Class;

    Class.prototype.super = _super.init;
    //Class.extend = arguments.callee;
    Class.extend = $.Class.extend;

    return Class;
}



var A = $.Class.extend({
    foo: 123,
    init: function(arg){
        console.log('Init ' + arg);
    },
    getFoo: function(){
        return this.foo;
    }
});

var a = new A('A');
console.log(a, a.getFoo());

var B = A.extend({
    bar: 'abc',
    init: function(arg){
        this.super('A' + arg);
        console.log('Init ' + arg);
    },
    getBar: function(){
        return this.bar + '{' + this.foo + '}';
    }
});

var b = new B('B');
console.log(b, b.getFoo(), b.getBar());