JSFiddle - React, Tailwind, and code Playground
JavaScript
var MeuObjeto = function() {
this.prop1 = "Olá, Mundo!";
this.prop2 = "Hahahaha";
this.recursivo = this;
this.funcao = function() {
return "retorno da função";
};
};
function stringify(algo) {
function checktype(obj) {
if (!obj || typeof obj == 'number' || typeof obj == 'string') return obj;
if (typeof obj == 'function') return obj.toString();
var _obj = Array.isArray(obj) ? [] : {};
Object.keys(obj).forEach(function(key) {
if (obj[key] == obj) _obj[key] = 'instance of itself';
else _obj[key] = checktype(obj[key]);
});
return _obj;
};
return JSON.stringify(checktype(algo), '\t', 4);
};
document.querySelector('pre').innerHTML = stringify(new MeuObjeto());