Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从子函数中完全分离javascript_Javascript - Fatal编程技术网

从子函数中完全分离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一样——并不是最好的选择。