Skip to content

Instantly share code, notes, and snippets.

@yulanggong
Created September 28, 2012 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yulanggong/3798444 to your computer and use it in GitHub Desktop.
Save yulanggong/3798444 to your computer and use it in GitHub Desktop.
deepRecursionCallback
var stackSize = 0;
function foo(a, stackSize){
stackSize ++;
bar();
if (!a.length) return;
if (stackSize > 1000) {
stackSize = 0;
setTimeout(function(){
a.forEach(function(item){
foo(item, stackSize)
});
},0)
} else {
a.forEach(function(item){
foo(item, stackSize)
});
}
}
foo(hugeArray, stackSize); //hugeArray 是一个多层嵌套的数组,像这样 [[[...],[...]],[...]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment