从子函数中完全分离javascript
简单的问题,我想从子函数中完全分离javascript,javascript,Javascript,简单的问题,我想 function foo1() { foo2(); // should not hit this line } function foo2() { foo3(); // should not hit this line } function foo3() { if(someCondition) // should not hit this line } 如果在foo3()中使用simple return,它将继续在foo2()
function foo1() {
foo2();
// should not hit this line
}
function foo2() {
foo3();
// should not hit this line
}
function foo3() {
if(someCondition)
// should not hit this line
}
如果在foo3()中使用simple return,它将继续在foo2()和foo3()中执行
我知道可以检查返回值等等,我只是想知道是否可以完全退出foo3()?要真正回答您的问题,当然,您可以从
foo3()
:
函数foo1(){
控制台日志(1)
foo2()
console.log(“从不命中”)
}
函数foo2(){
控制台日志(2)
foo3(3)
console.log(“从不命中”)
}
函数foo3(){
如果(真)
抛出“突破”
}
试一试{
foo1()
}捕获(e){
控制台日志(e)
}
这是纯javascript,我看不到任何angularJs
code退出函数的唯一方法是返回。@Merlin,是的,错误地添加了angular标记谢谢,真的))@monstro没问题,我最近看到一个有趣的话题(在Scala中)它使我确信,始终将错误视为值——就像稍后检查return
s一样——并不是最好的选择。