JSFiddle - React, Tailwind, and code Playground

by Aubrey Taylor

HTML

<div id="add"></div>
<div id="subtract"></div>

JavaScript

function MyClass(){
    var self = {}
    var index = 0;
    var now = +new Date();
    
    function __init__(){
        self.add = add;
        self.getDate = getDate;            
    }

    function add(v1, v2){
        return v1 + v2;                            
    }
    function getDate(){
        return now;                            
    }
    
    __init__();
    return self;
}
    
function math(){
    
    var self = {}              
    var wrapped = this;
  
    function __init__(){
        var inject = wrapped();
        
        for(key in inject){
            self[key] = inject[key];                
        }
        self.wrapped = inject;
        self.subtract = subtract;        
    }

    function subtract(v1,v2){
        return v1 - v2;                    
    }

    __init__();
    return self;
}

var obj = math.apply(MyClass);
console.log(obj.wrapped);
console.log(obj.getDate());
$("#add").text(obj.add(1,1));
$("#subtract").text(obj.subtract(1,1));