function sum(list) {
if (list.length===0) { throw new Error("not yet implemented"); }
const [head, ...tail] = list;
return helper1(()=>{
return head + sum(tail);
});
}
function helper1(f) {
try {
return helper2(f);
} catch(e) {
// here I'm supposed to try to handle the error
throw e;
}
}
function helper2(f) {
// here I'm supposed to increase indentation for loged messages...
const r = f();
// ...and now decrease it
return r;
}
try {
console.log(sum([7, 2, 3, 8]));
} catch(e) {
console.error(e.stack);
}
对于每次递归调用
sum
helper1
helper2
的其他调用,闭合传递给了helper1
有任何方法可以使堆栈跟踪中的这些助手功能保持沉默或隐藏?
如果问题主要与调试有关,则有一个解决方案:devtools脚本忽略list
。这使您可以从Callstack跟踪视图中删除无兴趣的功能。另请参见是否可以在chrome或firebox调试器中隐藏第三方js函数呼叫?
,avoid avoid avoid无关紧要的文件,同时调试在chrome中不起作用不起作用,
如何在调试中忽略内部reactionjs code in debugging stack中的内部reactionj code Reactjs.如果您实际上需要构成逻辑的堆栈,例如为了找到您在树数据架构中的位置,我建议您删除该方法,而不是通过
sum
数组(或保留您
path