JSFiddle - React, Tailwind, and code Playground

by alexflav23

JavaScript

var WeakMap = function() {
    this.keys = [];
    this.values = [];
};

WeakMap.prototype.get = function(key) {
    var index = this.keys.indexOf(key);
    return index != -1 ? this.values[index] : undefined;
};
WeakMap.prototype.set = function(key, value) {
    this.keys.push(key);
    this.values.push(value);
};
WeakMap.prototype.has = function(key) {
    return this.keys.indexOf(key) != -1;
};
WeakMap.prototype.delete = function(key) {
    var index = this.keys.indexOf(key);
    if (index != -1) {
       this.keys.splice(index, 1);
    };
};
WeakMap.prototype.clear = function(key) {
    this.keys.length = 0;
    this.values.length = 0;
};
var x = new WeakMap();
var y = new WeakMap();

var o_key = {};
// Set it on `x`
x.set(o_key, "foobar")

// we can get it from `y`
console.log(y.has(o_key)); // true
console.log(y.get(o_key)); // "foobar"