JSFiddle - React, Tailwind, and code Playground

by kentaromiura

JavaScript

var Class = function (descriptor) {
    var global = Function('return this')
    // class always return an instance of Object

    if (global === this) {
        return Class(descriptor)
    }

    var initialize = descriptor.initialize || function () {}
    delete descriptor.initialize

    var constructor = function constructor() {
        //construct
        var base = {}

        //modify
        for (var mutator in Class.Mutators) {
            if(Object.prototype.hasOwnProperty.call(Class.Mutators,mutator)){
                Class.Mutators[mutator](base, descriptor)
            }
        }

        //initialize
        initialize.apply(base, arguments)
        return base;

    }
    return constructor;
}

    function reset(obj) {
        var create = Object.create || function create(proto) {
                var f = function () {}
                f.prototype = proto
                return new f()
            }
        var gPO = Object.getPrototypeOf || function (obj) {
                return obj.__proto__ || obj.constructor.prototype
            }
        var _copy_ = create(gPO(obj));
        for (var key in obj) {
            var value = obj[key]
            _copy_[key] = value && typeof value === 'object' ? reset(value) : value
        }
        return _copy_
    }


Class.Mutators = {
    Implements: function (instance, descriptor) {
        var toImplement = descriptor.Implements;
        delete descriptor.Implements
        /*if (toImplement) {
            if (Array.isArray(toImplement)) { //isArray shim
                for (var i = 0, max = toImplement.length; i < max; i++) {
                    Class.Mutators.XCopy(instance, new toImplement[i]())
                }
            }
            if (typeof toImplement === 'object') {
                Class.Mutators.XCopy(instance, new toImplement())
            }
        }
        */
    },
    XCopy: function (instance, descriptor) {
        console.log('copying', descriptor)
        for (var prop in...