Object.prototype.deep_clone = function(){ eval("var tmp = " + this.toJSON()); return tmp; } Object.prototype.toJSON = function(){ var json = []; for(var i in this){ if(!this.hasOwnProperty(i)) continue; //if(typeof this[i] == "function") continue; json.push( i.toJSON() + " : " + ((this[i] != null) ? this[i].toJSON() : "null") ) } return "{\n " + json.join(",\n ") + "\n}"; } Object.prototype.toJSON = function(path, session){ var json = [], key, index, p; path = path || "self"; session = session || {path : [path], refs : [this]}; for(var i in this){ if(!this.hasOwnProperty(i)) continue; //if(typeof this[i] == "function") continue; key = i.toJSON(); if((index = session.refs.indexOf(this[i])) != -1){ json.push(key + " : " + session.path[index]) }else{ var p = path+"["+key+"]"; session.refs.push(this[i]) session.path.push(p); json.push( key + " : " + ((this[i] != null) ? this[i].toJSON(p,session) : "null") ) } } return "{\n " + json.join(",\n ") + "\n}"; } Array.prototype.toJSON = function(){ for(var i=0,json=[];i= ' ') ? (c == '\\') ? (tmp[i] = '\\\\'): (c == '"') ? (tmp[i] = '\\"' ): 0 : (tmp[i] = (c == '\n') ? '\\n' : (c == '\r') ? '\\r' : (c == '\t') ? '\\t' : (c == '\b') ? '\\b' : (c == '\f') ? '\\f' : (c = c.charCodeAt(),('\\u00' + ((c>15)?1:0)+(c%16))) ) } return '"' + tmp.join("") + '"'; }