...返回Math.random()含义?
每个人。
当我看到此代码时,我会感到困惑。 此代码是什么意思?为什么在返回此处之前使用传播操作员?
我尝试了使用节点的代码,它说意外的令牌'return'
fyi,此代码段来自nodejs文档。
function generateRandom() {
...return Math.random()
}
感谢任何解释。
everyone.
I am confused when I see this code.
What does this code mean? Why spread operator is used before return here?
I tried this code with node, and it says Unexpected token 'return'
Fyi, this code snippet is from nodejs document.
function generateRandom() {
...return Math.random()
}
Appreciate for any explanation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些点实际上并不是代码的一部分。它们只是 Node REPL 的一部分,在用户按下 Enter 后向用户发出指示,表明您键入的语句不完整。正如您找到此代码的链接所示:
也就是说,如果你开始输入:
然后按回车键,你会看到以下内容
,文本光标位于
...
的末尾,表明你需要在 REPL 之前完成该语句执行它。因此,
当您取出 REPL 的视觉指示器时,表明您处于多行模式,这在
语法上是正确的。
Those dots are not actually part of the code. They are a part of the Node REPL only, an indicator to the user, after they press enter, that the statement you've typed is not complete. As the link where you found this code says:
That is, if you start typing:
and then press enter, you'll see the following
with the text cursor at the end of the
...
, indicating that you need to finish the statement before the REPL executes it.So
when you take out the REPL's visual indicator that you're in multi-line mode, is just
which is syntactically correct.