我有一个功能:
function myfunction() {
if (a == 'stop') // How can I stop the function here?
}
JavaScript中是否有类似于exit()
的内容?
我有一个功能:
function myfunction() {
if (a == 'stop') // How can I stop the function here?
}
JavaScript中是否有类似于exit()
的内容?
你可以只用return
.
function myfunction() {
if(a == 'stop')
return;
}
这将向调用该函数的任何对象发送返回值undefined
.
var x = myfunction();
console.log( x ); // console shows undefined
当然,可以指定不同的返回值.返回的任何值都将使用上述示例记录到控制台.
return false;
return true;
return "some string";
return 12345;