我有一个函数,我调用它来删除一个点以外的任何东西,但有没有其他方法可以找到对它自己的引用并以某种方式删除该引用?
以下是我现在使用的内容:
//Changing the max level will speed things up, but it will mean that some things might not be persisted
function 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[i] = BackStack.cleanse(Obj[i], level + 1);
}
}
}
}
return r;
};