JSFiddle - React, Tailwind, and code Playground

by Alexander

JavaScript

"use strict";

console.clear();

var RM = RM || {};

(function(scope){
    if (!Object.create)
        Object.create = function(proto, prop){
            function F() {}
            F.prototype = proto;
            for (var k in prop) F[k] = prop[k].value;
            return new F;
        }

    function clone(){
        var clone, property, value, obj = this;
        if (!obj || typeof obj !== 'object') return obj;
        clone = typeof obj.pop === 'function' ? [] : {};
        //clone.__proto__ = obj.__proto__;
        clone.prototype = obj.prototype;
        for (property in obj) {
            //if (!obj.hasOwnProperty(property)) continue;
            value = obj.property;
            if (value && typeof value === 'object') {
                clone[property] = clone(value);
            } else {
                clone[property] = obj[property];
            }
        }
        return clone;
    }

    function ocf(obj){
        var o = {};

        for (var k in obj){
            o[k] = {
                value: obj[k]
            }
        }

        return o;
    }

	scope.Class = function(){};
	scope.Class.extend = function(prop){

		var _super = this.prototype;

        var prototype = Object.create(
            _super,
            ocf(prop)
        );

        prototype._super = function(){
            if (_super.init)
                return _super.init.apply(this, arguments);
        }

        //prototype.clone = clone;

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

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

		Class.extend = scope.Class.extend;

		return Class;
	};
})(RM);

var Class1 = RM.Class.extend({
    foo: 123,
    bar: 'dccdcdc',
    init: function(){
        console.warn('Init class 1', this.foo);
    },
    fTest1: function(){
        return "fTest in Class 1";
    }
});

var Class2 = Class1.extend({
    foo: 234,
    init: function(arg){
        console.warn('Init class 2: ' + arg);
       ...