简体   繁体   English

将变量分配给函数的输出

[英]Assigning a variable to the output of a function

So I'm trying to run a function, while returning its' return value to a variable, so that I can run another function with that information, but separately. 因此,我尝试运行一个函数,同时将其返回值返回给变量,以便我可以单独运行带有该信息的另一个函数。 I want to know if, when I do this, it actually runs the whole function. 我想知道是否在执行此操作时实际上运行了整个功能。 Example: 例:

function a() {
  blah blah blah;
  return b;
}
var c = a();
function d(x) {
  something with c;
}
d(c);

When I assign a() to c, does that run a()? 当我为c分配a()时,是否运行a()? or just find the return value, and return it. 或者只是找到返回值,然后将其返回。 I would greatly appreciate this! 我将不胜感激! Thanks. 谢谢。

是的,它运行a()函数,并且您应该能够在d(x)函数中将c与a()返回的值一起使用。

var c = a()

will execute function a, and store the results in the var c. 将执行功能a,并将结果存储在var c中。

If you want to refer to the function itself and not what is returned from executing the function, you would write: 如果要引用函数本身而不是执行函数返回的内容,则应编写:

var c = a

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

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