You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过给定的三个JavaScript函数实现指定顺序的控制台输出?

问题分析

你的问题出在third(second(first))的调用逻辑上:

  • second(first)执行时会打印first和second,但该函数没有返回值,默认返回undefined
  • 所以third接收的参数是undefined,当third内部执行second()时,就会抛出“second is not a function”的错误
解决方案

你需要给third传入一个函数类型的参数,让这个参数函数内部去调用second(first),这样就能按要求输出顺序。具体调用代码如下:

third(() => second(first));

执行流程:

  1. 调用third并传入一个匿名函数
  2. third内部执行传入的匿名函数,触发second(first)
  3. second内部执行first()打印first,接着打印second
  4. 回到third,最后打印third

最终控制台会依次输出:

first
second
third

内容的提问来源于stack exchange,提问作者Norman D

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 23:44:55