Removing circular objects

mkzbikp

New Member
I have a function which I call to cut of anything beyond a point, but is there any other way to find a reference to itself and remove that reference somehow smartly?Here is what I am using now:\[code\]//Changing the max level will speed things up, but it will mean that some things might not be persistedfunction cleanse(Obj, level) { var r, i, prims = ["string", "number", "boolean"], maxLevel = 8; level = level || 0; if (prims.indexOf(typeof Obj) !== -1) { r = Obj; } else if (Obj instanceof Function) { console.log("Please dont reference objects"); return undefined; } else { if (Obj instanceof Array) { r = []; } else { r = {}; } for (i in Obj) { if (Obj.hasOwnProperty(i)) { if (level <= maxLevel) { r = BackStack.cleanse(Obj, level + 1); } } } } return r;};\[/code\]
 
Back
Top