JSFiddle - React, Tailwind, and code Playground

by amatiasq

HTML

<script src="http://amatiasq.com/fiddle-console.js"></script>

JavaScript

function $new() {
    var instance = Object.create(this);
    instance.constructor.apply(this, arguments);
    return instance;
}

var MyNumber = {
    _cache: {},
    new: function(value) {
        if (this._cache[value])
            return this._cache[value];
        
        var instance = $new.apply(this, arguments);
        this._cache[value] = instance;
        return instance;
    },
    
    constructor: function(value) {
        this.value = value;
    },
};

var num1 = MyNumber.new(3);
var num2 = MyNumber.new(3);

console.log(num1.value);
console.log(num1 === num2);