代码改变世界

标记清除算法

2017-07-23 18:42  Dirichlet  阅读(200)  评论(0编辑  收藏  举报

function mark(p, level){
  if(level >3){
     return ;
  }

  if(typeof p == "object" && p != null && p.marked == undefined){

  p.marked = true;
  console.log(p);
  
  for(var prop in p){
     mark(p[prop], level+1);
  }
 }
}

var g1={name:"xiaoming"};

function func1(){
   return {name:"xiaohua"};
}

var l2 = func1();

mark(window, 1);