本文介绍了让函数“返回".超级功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下代码:

function two() {
    return "success";
}

function one() {
    two();
    return "fail";
}

如果通过调用函数one()测试代码,则始终会出现失败"的情况.

If you test the code by calling function one(), you will always get "fail".

问题是,如何仅通过调用函数two()在函数one()中返回成功"?

The question is, how can I return "success" in function one() by only calling function two()?

那有可能吗?

致谢

推荐答案

您无法使函数从用Javascript(或许多其他语言,afaik)调用过的函数返回.您需要在one()中执行逻辑.例如:

You can't make a function return from the function that called it in Javascript (or many other languages, afaik).You need logic in one() to do it. E.g.:

 function one() {
     return two() || "fail";
 }

这篇关于让函数“返回".超级功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 08:38