JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

JavaScript

var Person = (function () {
    var id = 0,
        data = {},
        key = Math.random();

    function Person(age) {
        var thisId = id;
        
        data[id] = age;
        id += 1;
        
        this.getId = function(check) {
            if (check !== key) {
                return undefined;
            }
            
            return thisId;
        };
    }
    
    Person.prototype.grow = function () {
        var thisId = this.getId(key);
        
        data[thisId] += 1;
        console.log(data[thisId]);
        
        return this;
    };
    
    Person.prototype.destroy = function () {
        var thisId = this.getId(key);
        
        data[thisId] = null;
        delete data[thisId];
    };
    
    return Person;
}());

var dan = new Person(10);

dan.grow();
console.log(dan.age); // undefined
console.log(dan.getId()); // undefined