我有一个功能:
function myfunction() {
if (a == 'stop') // How can I stop the function here?
}
Run Code Online (Sandbox Code Playgroud)
是否有类似exit()JavaScript的东西?
我需要一个能退出js脚本的代码,就像PHP'exit'或'die'一样.(我知道它不是最好的编程实践,但我需要它).
我的目标是:
if(error){
window.location.href = "error.htm";
//end of every thing
}
Run Code Online (Sandbox Code Playgroud)
而且,return false由于功能内部可能存在功能,因此无济于事。我当前的解决方案是throw,但我感到不舒服
任何更好的主意|| 解决方案