代码之家  ›  专栏  ›  技术社区  ›  ptter

VScode Code Runner扩展在不询问的情况下执行循环

  •  0
  • ptter  · 技术社区  · 2 年前

    所以,我是一个新手,我有一个简单的js文件来打印几个字符串,而不需要任何循环。 我通过vscode Code Runner扩展来运行它。 输出只是反复循环我的程序,直到nodejs将其关闭。

    这是我的代码和错误信息,thx my code error message

    我已经用代码运行器测试了另一个简单的文件,它运行得很好

    我想知道是不是有些设置我做错了 或者只是CodeRunner扩展被破坏了?

    1 回复  |  直到 2 年前
        1
  •  1
  •   MrDiamond    2 年前

    你在打电话 fun() 从内部 fun() 。这是递归,并导致无限循环。

    对于下一次,请将代码和错误发布为三个反引号(``)包围的文本,而不是图像。

    以下是正确的代码:

    function fun(z) {
      console.log(`we have a argument named z`)
      console.log(`print by call the argumentName: ${z}`)
      console.log(`print by call the argument.length: ${arguments.length}`)
      console.log(`print by call the this.length: ${this.length}`)
      console.log(`print by call the functionName.length: ${fun.length}`)
    
      // This line is calling `fun()` from inside `fun()`, causing an infinite loop.
      // console.log(`print by call the functionName().length: ${fun().length}`)
    }
    let a = 5
    fun(a);
    
    推荐文章