JSFiddle - React, Tailwind, and code Playground

by gabrieleromanato

JavaScript

Object.prototype._clone = function() {
    var o = {};
    for (var property in this) {
        o[property] = typeof(this[property]) === 'object' ? this[property]._clone() : this[property];
    }
    return o;
}

Array.prototype._clone = function() {
    var a = [];
    for (var property in this) {
        a[property] = typeof(this[property]) === 'object' ? this[property]._clone() : this[property];
    }
    return a;
}


var o1 = {
    test: 'Test'
};
var clone1 = o1._clone();
alert(clone1.test);


var a1 = ['a', 1];
var clone2 = a1._clone();
alert(clone2[1]);