简体   繁体   English

如果语句不起作用,则使用简写返回

[英]Using return in shorthand if statement doesn't work

I can't seem to understand why does this work: 我似乎无法理解为什么这样做:

if(n < i)
{
    functoin();
}
else
{
    return;
}

While this doesn't work: 虽然这不起作用:

(n < i) ? function() : return;

why does the shorthand if-statement doesn't work? 为什么速记if语句不起作用?

return can't be used in an expression. return不能在表达式中使用。 Maybe you can try, 也许你可以尝试,

return (n < i) ? function() : undefined;

But that's only if you have one thing to do for each condition. 但是,只有你对每种情况都有一件事要做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM