Created
September 28, 2012 07:23
-
-
Save yulanggong/3798444 to your computer and use it in GitHub Desktop.
deepRecursionCallback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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